Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Let's say in your <code>settings.py</code> file you have:</p> <pre><code>SITE_URL='www.mydomain.tld/somewhere/' SITE_NAME='My site' </code></pre> <p><strong>If you need that in just one or two views:</strong></p> <pre><code>from django.shortcuts import render_to_response from django.conf import settings def my_view(request, ...): response_dict = { 'site_name': settings.SITE_NAME, 'site_url': settings.SITE_URL, } ... return render_to_response('my_template_dir/my_template.html', response_dict) </code></pre> <p><strong>If you need to access these across a lot of apps and/or views, you can write a context processor to save code:</strong></p> <p>James has a tutorial on this <a href="http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/" rel="noreferrer">online</a>.</p> <p>Some useful information on the when and if of context processors is available on this very site <a href="https://stackoverflow.com/questions/831301/when-is-it-appropriate-to-use-django-context-processors">here</a>.</p> <p>Inside your <code>my_context_processors.py</code> file you would:</p> <pre><code>from django.conf import settings def some_context_processor(request): my_dict = { 'site_url': settings.SITE_URL, 'site_name': settings.SITE_NAME, } return my_dict </code></pre> <p>Back in your <code>settings.py</code>, activate it by doing:</p> <pre><code>TEMPLATE_CONTEXT_PROCESSORS = ( ... # yours 'my_context_processors.some_context_processor', ) </code></pre> <p>In your <code>views.py</code>, make a view use it like so:</p> <pre><code>from django.shortcuts import render_to_response from django.template import RequestContext def my_view(request, ...): response_dict = RequestContext(request) ... # you can still still add variables that specific only to this view response_dict['some_var_only_in_this_view'] = 42 ... return render_to_response('my_template_dir/my_template.html', response_dict) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload