diff options
| author | Keryn Knight <keryn@kerynknight.com> | 2015-01-13 08:02:17 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-01-16 09:41:01 -0500 |
| commit | 726a9550db5129badc1c44809b0bed728fa1ad90 (patch) | |
| tree | 783f0146d577359f789234f75fa69f5dae5c66b9 /docs | |
| parent | a34fba5e596a3ec95bf284fd77b1609e71a65019 (diff) | |
Fixed #24143 -- Encouraged use of Http404 messages for debugging.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/intro/tutorial03.txt | 2 | ||||
| -rw-r--r-- | docs/ref/contrib/sites.txt | 2 | ||||
| -rw-r--r-- | docs/topics/http/shortcuts.txt | 4 | ||||
| -rw-r--r-- | docs/topics/http/views.txt | 7 |
4 files changed, 10 insertions, 5 deletions
diff --git a/docs/intro/tutorial03.txt b/docs/intro/tutorial03.txt index c4590abf23..83ed0cff70 100644 --- a/docs/intro/tutorial03.txt +++ b/docs/intro/tutorial03.txt @@ -442,7 +442,7 @@ for a given poll. Here's the view: try: question = Question.objects.get(pk=question_id) except Question.DoesNotExist: - raise Http404 + raise Http404("Question does not exist") return render(request, 'polls/detail.html', {'question': question}) The new concept here: The view raises the :exc:`~django.http.Http404` exception diff --git a/docs/ref/contrib/sites.txt b/docs/ref/contrib/sites.txt index da7b73caed..91fbd2af85 100644 --- a/docs/ref/contrib/sites.txt +++ b/docs/ref/contrib/sites.txt @@ -88,7 +88,7 @@ This accomplishes several things quite nicely: try: a = Article.objects.get(id=article_id, sites__id=get_current_site(request).id) except Article.DoesNotExist: - raise Http404 + raise Http404("Article does not exist on this site") # ... .. _ljworld.com: http://www.ljworld.com/ diff --git a/docs/topics/http/shortcuts.txt b/docs/topics/http/shortcuts.txt index d31572dd4d..f015786838 100644 --- a/docs/topics/http/shortcuts.txt +++ b/docs/topics/http/shortcuts.txt @@ -313,7 +313,7 @@ This example is equivalent to:: try: my_object = MyModel.objects.get(pk=1) except MyModel.DoesNotExist: - raise Http404 + raise Http404("No MyModel matches the given query.") The most common use case is to pass a :class:`~django.db.models.Model`, as shown above. However, you can also pass a @@ -383,4 +383,4 @@ This example is equivalent to:: def my_view(request): my_objects = list(MyModel.objects.filter(published=True)) if not my_objects: - raise Http404 + raise Http404("No MyModel matches the given query.") diff --git a/docs/topics/http/views.txt b/docs/topics/http/views.txt index 810bbc3512..86657d2c65 100644 --- a/docs/topics/http/views.txt +++ b/docs/topics/http/views.txt @@ -119,13 +119,18 @@ Example usage:: try: p = Poll.objects.get(pk=poll_id) except Poll.DoesNotExist: - raise Http404 + raise Http404("Poll does not exist") return render_to_response('polls/detail.html', {'poll': p}) In order to use the ``Http404`` exception to its fullest, you should create a template that is displayed when a 404 error is raised. This template should be called ``404.html`` and located in the top level of your template tree. +If you provide a message when raising an ``Http404`` exception, it will appear +in the standard 404 template displayed when :setting:`DEBUG` is ``True``. Use +these messages for debugging purposes; they generally aren't suitable for use +in a production 404 template. + .. _customizing-error-views: Customizing error views |
