× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Django 1.8 changes to urls and template settings

Jessamyn Smith
May 11, 2015
<p>Django 1.8 has some very important changes relative to earlier versions. If you are incorporating code examples, you need to be aware of this.</p> <p>One change is to urls. The old way used patterns, like so:</p> <pre><strong>from </strong>django.conf.urls <strong>import </strong>patterns, include, url from . import views urlpatterns = patterns( url(<strong>r'^articles/2003/$'</strong>, <strong>views.special_case_2003</strong>), )</pre> <p>Django 1.8 uses lists:</p> <pre><strong>from</strong> <strong>django.conf.urls</strong> <strong>import</strong> url <strong>from</strong> <strong>.</strong> <strong>import</strong> views urlpatterns <span style="color:rgb(102, 102, 102)">=</span> [ url(<span style="color:rgb(186, 33, 33)">r'^articles/2003/$'</span>, views<span style="color:rgb(102, 102, 102)">.</span>special_case_2003), ]</pre> <p>Another important change is to configuration for templates. In the old way, you set up various settings values, e.g.</p> <pre><span style="background-color:#ffe4ff">TEMPLATE_DIRS</span> = (<em> </em><em> </em>BASE_DIR + <strong>'/lunahealing/templates/'</strong>, )</pre> <p>In Django 1.8, all settings are brought together under TEMPLATES:</p> <pre><span style="background-color:#ffe4ff">TEMPLATES</span> = [ { <strong>'BACKEND'</strong>: <strong>'django.template.backends.django.DjangoTemplates'</strong>, <strong>'DIRS'</strong>: [os.path.join(MAIN_DIR, <strong>'templates'</strong>)], <strong>'APP_DIRS'</strong>: <span style="color:#000080">True</span>, <strong>'OPTIONS'</strong>: { <strong>'context_processors'</strong>: [ <strong>'django.template.context_processors.debug'</strong>, <strong>'django.template.context_processors.request'</strong>, <strong>'django.contrib.auth.context_processors.auth'</strong>, <strong>'django.contrib.messages.context_processors.messages'</strong>, ], }, }, ]</pre>
comments powered by Disqus