Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Django provides access to certain, frequently-used settings constants to the template such as <code>settings.MEDIA_URL</code> and some of the language settings if you use django's built in generic views or pass in a context instance keyword argument in the <code>render_to_response</code> shortcut function. Here's an example of each case:</p> <pre><code>from django.shortcuts import render_to_response from django.template import RequestContext from django.views.generic.simple import direct_to_template def my_generic_view(request, template='my_template.html'): return direct_to_template(request, template) def more_custom_view(request, template='my_template.html'): return render_to_response(template, {}, context_instance=RequestContext(request)) </code></pre> <p>These views will both have several frequently used settings like <code>settings.MEDIA_URL</code> available to the template as <code>{{ MEDIA_URL }}</code>, etc.</p> <p>If you're looking for access to other constants in the settings, then simply unpack the constants you want and add them to the context dictionary you're using in your view function, like so:</p> <pre><code>from django.conf import settings from django.shortcuts import render_to_response def my_view_function(request, template='my_template.html'): context = {'favorite_color': settings.FAVORITE_COLOR} return render_to_response(template, context) </code></pre> <p>Now you can access <code>settings.FAVORITE_COLOR</code> on your template as <code>{{ favorite_color }}</code>. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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