Last change
on this file since 695d358 was
21360c8,
checked in by Alex Dehnert <adehnert@…>, 11 years ago
|
Django 1.6: Switch to class-based ListView?
Dango 1.5(?) removed function-based generic views, so we need to switch to the
class-based ones.
|
-
Property mode set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[f7dd5e7] | 1 | from django.http import HttpResponseForbidden |
---|
| 2 | from django.template import RequestContext, Template |
---|
| 3 | from django.template.loader import get_template |
---|
[21360c8] | 4 | from django.views.generic.base import TemplateView |
---|
| 5 | from django.views.generic.list import ListView |
---|
[f7dd5e7] | 6 | |
---|
| 7 | def get_403_response(request, errmsg=None, **extra_context): |
---|
| 8 | tmpl = get_template('403.html') |
---|
| 9 | ctx = RequestContext(request, dict(errmsg=errmsg, **extra_context)) |
---|
| 10 | page = tmpl.render(ctx, ) |
---|
| 11 | return HttpResponseForbidden(page) |
---|
[21360c8] | 12 | |
---|
| 13 | |
---|
| 14 | class ListViewWithContext(ListView): |
---|
| 15 | extra_context = {} |
---|
| 16 | |
---|
| 17 | # I believe .queryset will work out-of-the-box |
---|
| 18 | |
---|
| 19 | def get_context_data(self, **kwargs): |
---|
| 20 | context = super(ListViewWithContext,self).get_context_data(**kwargs) |
---|
| 21 | context.update(self.extra_context) |
---|
| 22 | return context |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | class TemplateViewWithContext(TemplateView): |
---|
| 26 | extra_context = {} |
---|
| 27 | |
---|
| 28 | def get_context_data(self, **kwargs): |
---|
| 29 | context = super(TemplateViewWithContext,self).get_context_data(**kwargs) |
---|
| 30 | print context |
---|
| 31 | context.update(self.extra_context) |
---|
Note: See
TracBrowser
for help on using the repository browser.