diff --git a/docs/intro/tutorial03.txt b/docs/intro/tutorial03.txt index 59e68ef6bb..95f0dca7b4 100644 --- a/docs/intro/tutorial03.txt +++ b/docs/intro/tutorial03.txt @@ -441,7 +441,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 b3f33c8da8..dc6cea46bb 100644 --- a/docs/ref/contrib/sites.txt +++ b/docs/ref/contrib/sites.txt @@ -84,7 +84,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 d64ec2f7cb..c167fa4762 100644 --- a/docs/topics/http/shortcuts.txt +++ b/docs/topics/http/shortcuts.txt @@ -299,7 +299,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 @@ -369,4 +369,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 41853b76ca..121c4a9423 100644 --- a/docs/topics/http/views.txt +++ b/docs/topics/http/views.txt @@ -121,13 +121,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