Django

Code

root/django/trunk/django/views/defaults.py

Revision 9001, 1.4 kB (checked in by adrian, 10 months ago)

Moved the bulk of the shortcut() function in django/views/defaults.py to a new module, django/contrib/contenttypes/views.py. As a result, django/views/defaults.py no longer relies on django.contrib.contenttypes. Of course, the shortcut() function is still available in the former module, for backwards compatibility. See the new FutureBackwardsIncompatibleChanges wiki page.

  • Property svn:eol-style set to native
  • Property svn:keywords set to LastChangedRevision
Line 
1 from django import http
2 from django.template import Context, RequestContext, loader
3
4 def page_not_found(request, template_name='404.html'):
5     """
6     Default 404 handler.
7
8     Templates: `404.html`
9     Context:
10         request_path
11             The path of the requested URL (e.g., '/app/pages/bad_page/')
12     """
13     t = loader.get_template(template_name) # You need to create a 404.html template.
14     return http.HttpResponseNotFound(t.render(RequestContext(request, {'request_path': request.path})))
15
16 def server_error(request, template_name='500.html'):
17     """
18     500 error handler.
19
20     Templates: `500.html`
21     Context: None
22     """
23     t = loader.get_template(template_name) # You need to create a 500.html template.
24     return http.HttpResponseServerError(t.render(Context({})))
25
26 def shortcut(request, content_type_id, object_id):
27     # TODO: Remove this in Django 2.0.
28     # This is a legacy view that depends on the contenttypes framework.
29     # The core logic was moved to django.contrib.contenttypes.views after
30     # Django 1.0, but this remains here for backwards compatibility.
31     # Note that the import is *within* this function, rather than being at
32     # module level, because we don't want to assume people have contenttypes
33     # installed.
34     from django.contrib.contenttypes.views import shortcut as real_shortcut
35     return real_shortcut(request, content_type_id, object_id)
Note: See TracBrowser for help on using the browser.