Django custom 404 not working..context variable not showing

I am using django 1.6

In myapp1 / urls.py

from django.conf.urls import patterns, include, url, handler404  

# url patterns ... 
#  
#  

handler404 = 'myapp1.views.custom_page_not_found'


myapp1 / views.py

def custom_page_not_found (request):

    ## 404 custom code start ##
    ### some query set here
    context = {}
    context ['var1'] = qs1

    resp = render_to_response ('404.html', context, context_instance = RequestContext (request))
    resp.status_code = 404
    return resp

    ## 404 custom code end ##    


myapp1 / templates / 404.html

<!-- html code bla bla bla -->

<ul>
{% for x in var1 %}
<li>{{x.name}}</li>
{% endfor %}
</ul>

      


I have tested the code using dummy / test view in debug / development and it works.
But when I put the code inside custom_page_not_found

, the rendered 404 page on the real server is empty between<ul></ul>

reference

EDIT: After further research, it seems that my custom view is not being called. Django still uses its own 404 view by default. Still don't know the solution :(

+3


source to share





All Articles