There is another way. The code page_not_found uses RequestContext ; this means that you have access to all the variables defined by all context handlers defined in the TEMPLATE_CONTEXT_PROCESSORS entry in settings.py . The default value includes, among other things, the django message structure.
So, you can define the message you want to show using messages.error , for example, and show the message in the template using the messages variable.
In other words, you can write your opinion as follows:
from django.contrib import messages from django.http import Http404 from django.template import RequestContext def my_view(request):
In your 404.html template, you should write something like:
{% if messages %} <ul class="messages"> {% for message in messages %} <li>{{ message }}</li> {% endfor %} </ul> {% endif %}
This is a bit more complicated, but has the advantage that you can send multiple messages and even use different messages (warning, debugging, information, error, etc.). You can learn more about django's message structure here: Message Structure | Django Documentation .
Euribates Apr 18 '13 at 18:24 2013-04-18 18:24
source share