How to properly setup custom handler404 in django? : <p>According to the <a href="https://docs.djangoproject.com/en/dev/topics/http/views/#customizing-error-views" rel="noreferrer">documentation</a> this should be fairly simple: I just need to define <code>handler404</code>. Currently I am doing, in my top <code>urls.py</code>:</p>

<pre><code>urlpatterns = [
    ...
]

handler404 = 'myapp.views.handle_page_not_found'
</code></pre>

<p>The application is installed. The corresponding view is just (for the time being I just want to redirect to the homepage in case of 404):</p>

<pre><code>def handle_page_not_found(request):
    return redirect('homepage')
</code></pre>

<p>But this has no effect: the standard (debug) <code>404</code> page is shown.</p>

<p>The documentation is a bit ambiguous:</p>

<ul>
<li>where should <code>handler404</code> be defined? The documentation says in the <code>URLconf</code> but, where exactly? I have several applications, each with a different <code>urls.py</code>. Can I put it in any of them? In the top <code>URLconf</code>? Why? Where is this documented?</li>
<li>what will be catched by this handler? Will it catch <code>django.http.Http404</code>,  <code>django.http.HttpResponseNotFound</code>, <code>django.http.HttpResponse</code> (with <code>status=404</code>)?</li>
</ul>
