Given
siteInfo = \
{
'appname3': 'MSQuantDynamics11',
'siteBase': 'http://www.pil.sdu.dk/1',
}
in a "urls.py" file.
This works as expected:
urlpatterns = patterns('',
(r'^$', direct_to_template, \
{ \
'template' : "homepage.html", \
'extra_context': { 'siteInfo': siteInfo }, \
}
),
)
Why does it not work with the following? (The result of "{{ siteInfo.appname3 }}" in homepage.html becomes emtpy):
urlpatterns = patterns('',
(r'^$', direct_to_template, \
{ \
'template' : "homepage.html", \
'extra_context': siteInfo, \
}
),
)
Would it work if "siteInfo.appname3" was changed to something else?
Use {{ appname3 }} instead of {{siteInfo.appname3}} .
Because key-value pairs {{appname3}} can be directly accessible in the template, rather than accessible through {{ siteInfo.key }}.
In the first example, you're creating a dict to be passed into extra_context, with the key siteInfo, and the value being the dict siteInfo. In the second, you're passing the dict siteInfo directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With