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
python django


source to share


No one has answered this question yet

Check out similar questions:

3
How to use RequestContexts in render_to_response in Django 1.8
2
Django page not found, ajax request not working correctly
2
How to render custom 404.html page in Django
1
Page not found (404) django
1
404 error to receive request from AJAX call in django view
0
ajax request to view in Django producing 404
0
one pattern - multiple model errors
0
Page not found in Django (404)
-1
django - Page not found (404)
-2
Page not found (404) error in Django



All Articles
Loading...
X
Show
Funny
Dev
Pics