djangosnippets.org: Latest snippets tagged with 'contextprocessor'https://djangosnippets.org/tags/contextprocessor/2013-12-12T03:57:44.527969-06:00Lazy context processor.
2013-12-12T03:57:44.527969-06:00spookylukeyhttps://djangosnippets.org/snippets/3011/<p>Sometimes you have context variables that are needed on many pages in a site, but not all. You only want them to be evaluated when actually needed, especially if they are expensive calculations that do DB queries etc. The pattern to use is shown: put a callable into the context, …</p>
Freely redistributablePropertyBasedContext
2011-07-13T07:22:01.282462-05:00a4tunadohttps://djangosnippets.org/snippets/2486/<p>This approach allows you to avoid code duplication to produce same context data for different views. </p>
<p>It could be usefull when you are using templates inheritace.</p>
Freely redistributableUsing URLs for highlighting sections in menu
2010-08-09T17:15:18.659869-05:00divermanhttps://djangosnippets.org/snippets/2143/<p>Use this, if you want to "activate" menu items by URL. Typical usage is with CSS class 'active'.</p>
Freely redistributableAdd site info to request context
2008-11-17T14:35:58.925128-06:00bthomashttps://djangosnippets.org/snippets/1197/<p>Sometimes you want to generate a <strong>really</strong> absolute URL, but the built-in url tag only generates a URL relative to the current domain. This context processor adds the extra information needed to the request context, so you can generate an absolute URL in a template like so:
</p>
<p><code>{{ protocol }}://{{ …</code></p>
Freely redistributableYet another SQL debugging facility
2007-08-16T11:52:43.596983-05:00miracle2khttps://djangosnippets.org/snippets/370/<p>Inspired by http://www.djangosnippets.org/snippets/159/</p>
<p>This context processor provides a new variable {{ sqldebug }}, which can
be used as follows:</p>
<p>{% if sqldebug %}...{% endif %}
{% if sqldebug.enabled %}...{% endif %}</p>
<pre><code>This checks settings.SQL_DEBUG and settings.DEBUG. Both need to be True,
otherwise the above will evaluate to False and sql …</code></pre>
Freely redistributable