I'm trying to override a url in django-profiles to raise a 404 instead of passing to the view.
I'm looking for something along the lines of:
url(r'^profiles/$', lamdba x: raise Http404)
But the above doesn't work. Is this sort of thing possible?
I know I can write a new view that raises a 404, but I'd rather not if I can do it in the url pattern directly.
edit: Specifically, I get invalid syntax (urls.py, line 29)
with the above example.
Starting from Django 1.9, the page_not_found
view now "accepts a second parameter, the exception that triggered the error." So the solution proposed above by Christoffer requires some minor change:
from django.views.defaults import page_not_found
urlpatterns = patterns('',
url(r'^profiles/$', page_not_found, {'exception': Exception('Not Found')}),
)
Hope this helps.
Just use the view django.views.defaults.page_not_found
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With