Во-первых, создайте способ иметь Ваши серверы разработки, и рабочие серверы вытягивают настройки из различных файлов, говорят dev.py и prod.py. Существует много способов сделать это.
Затем создайте установку, GOOGLE_ANALYTICS_KEY
. В dev.py устанавливает его на пустую строку. В prod.py, набор это к Вашему ключу, чему-то как "UA-124465-1". Создайте процессор контекста, чтобы добавить эту установку на все Ваши шаблонные контексты, или как GOOGLE_ANALYTICS_KEY
, или просто идти вперед и добавить Ваш модуль настроек. Затем в Вашем шаблоне используйте его для условного включения кода аналитики:
{% if settings.GOOGLE_ANALYTICS_KEY %}
{% endif %}
Это работает на меня, и легко добавить/удалить особые случаи. Работы с CSS, HTML и JS.
function inline_trim($t)
{
$t = preg_replace('/>\s*\n\s*</', '><', $t); // line break between tags
$t = preg_replace('/\n/', ' ', $t); // line break to space
$t = preg_replace('/(.)\s+(.)/', '$1 $2', $t); // spaces between letters
$t = preg_replace("/;\s*(.)/", ';$1', $t); // colon and letter
$t = preg_replace("/>\s*(.)/", '>$1', $t); // tag and letter
$t = preg_replace("/(.)\s*</", '$1<', $t); // letter and tag
$t = preg_replace("/;\s*</", '<', $t); // colon and tag
$t = preg_replace("/;\s*}/", '}', $t); // colon and curly brace
$t = preg_replace("/(.)\s*}/", '$1}', $t); // letter and curly brace
$t = preg_replace("/(.)\s*{/", '$1{', $t); // letter and curly brace
$t = preg_replace("/{\s*{/", '{{', $t); // curly brace and curly brace
$t = preg_replace("/}\s*}/", '}}', $t); // curly brace and curly brace
$t = preg_replace("/{\s*([\w|.|\$])/", '{$1', $t); // curly brace and letter
$t = preg_replace("/}\s*([\w|.|\$])/", '}$1', $t); // curly brace and letter
$t = preg_replace("/\+\s+\'/", "+ '", $t); // plus and quote
$t = preg_replace('/\+\s+\"/', '+ "', $t); // plus and double quote
$t = preg_replace("/\'\s+\+/", "' +", $t); // quote and plus
$t = preg_replace('/\"\s+\+/', '" +', $t); // double quote and plus
return $t;
}