1π
Its about time you started using the generic class based views, which will automatically pass in the request context, which will make session data available in your templates.
You will have to enable the template request context processor which will give you a {{ request }}
variable at the template level.
Here is an example using ListView
:
from django.conf.urls import patterns
from django.views.generic.list import ListView
urlpatterns = patterns('',
(r'^support/slp/$',
ListView.as_view(template_name="pages_fixed/support/support_slp.html",
queryset=Question.objects.filter(show_slp=True).order_by('seq_num')),
)
In your support_slp.html
template, youβll have a object_list
variable that will be result of the queryset and you can use {{ request.session.user_state }}
in the template.
0π
This could easily be done in a custom template tag. Inclusion and assignment tags can optionally accept the existing context, which includes the request if you have the request context processor activated. You can use that to access the session.
- [Answer]-Django getting related foreignkey fields confusion
- [Answer]-How to direct to a webpage in urls.py without using a view
- [Answer]-In django(1.5.4) model form how do i get the admin type date and time selector?
- [Answer]-Can't start Django 1.7.1 development server
- [Answer]-How to save foreign key referenced model instance when parent model instance is created in Django
0π
You could use a custom context processor to feed whatever you need into the context of all the pages. Suppose you put this code in package_name/context_processors.py
def session_data(request):
return {
'user_state': request.session['user_state'],
}
The you specify this context processor in TEMPLATE_CONTEXT_PROCESSORS
in the settings file:
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.request',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'package_name.context_processors.user_data')
More documentation on context processors available here
- [Answer]-How to implement user specific real time notifications in django using swampdragon?
- [Answer]-Socket communication with Django
- [Answer]-Urls with ".html" suffix in FlatPages