Django how to send a argument in handler404?
<p>How to override <code>handler404</code> to pass arguments into view?</p>

<p>Need to pass the arguments <code>text</code> and <code>error</code></p>

<pre><code># views.py
def handler404(request, error, text):
    response = render_to_response('error/40X.html', {'error': error, 'text':text})
    response.status_code = error
    return response
</code></pre>

<p>And the override code 404 errors:</p>

<pre><code>handler404 = 'app.views.handler404'
</code></pre>

<p>Am using Django v1.10 and Python v3.5, and do not really want to create a function for each error.</p>

<blockquote>
  <p>The question was translated, and I would be grateful for corrections, <a href="http://ru.stackoverflow.com/questions/568820/django-%D0%BA%D0%B0%D0%BA-%D0%BE%D1%82%D0%BF%D1%80%D0%B0%D0%B2%D0%B8%D1%82%D1%8C-%D0%B0%D1%80%D0%B3%D1%83%D0%BC%D0%B5%D0%BD%D1%82-%D0%B2-handler404">original</a></p>
</blockquote>

<p>I don't think you need a custom <code>handler404</code> view here. Django's <code>page_not_found</code> view does what you want.</p>

<p>In Django 1.9+, you can include <code>{{ exception }}</code> in the 404 template.</p>

<p>In your view, you could set the message when raising the exception, for example:</p>

<pre><code>from django.http import Http404

def my_view(request):
    raise Http404('custom error message')
</code></pre>

<p>It doesn't make sense to set <code>response.status_code</code> in the handler - if it's handler404, then the status code should always be 404.</p>

python django python-3.x django-views python-3.5