Tuesday, September 23, 2014

Re: Django url pass through

-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - https://gpgtools.org

iQIcBAEBCgAGBQJUISVuAAoJEB267zEX1rwQh0YP/2AfkW8mQ5lA7vzDUylWr0G3
EOst1QgXz6N32cXBD1Pww80fRcAnvZHfecal1GmnwJ53iCbgHUHq4Pu+cmNf3rSO
uYOScQRGxCgz7C7HCB0MkMVsy7ovRTWSJsZeSH8jJ4M0DkxWou6MF8shgVQhU/ki
C19Oirx6lHbGtDBCaAZgLk3VN52krduICRDBAxMDzmAQERIcWYFz1VIA+UbroOiQ
+cKyeUqUh1sp2ZUwviYBmsLPM4peCsWpmIewrlm9vU5rnREr6X4nmkV4u77NciPi
dtF3k/JTGpyPdRR1r7ogwofIIe4WE7L/QSfmPdVTrq50/5N1zTtba99+hNpsUQMl
2WnpS7nKOVKR5lAB8jjh6qQg1fO6l1vGz4Nh9LwHuseedLHCNUTykIw77PsxmIk9
MXhhlGXNXiPo/lnX20CrK4DLRL/3mjS4adBdmGYtJt+iZA4t/cUzUj9fBrT/XOZI
6v5BWduEP1CiZpZiZgIFdTfyN0DOfHG146CLmwgMf6xYvvh4XcxEBJ6sw/0la6DR
gYKkBApD6xTEJU8CtzzY9oXURaYg0YgS1SrUpFmD/jloh9jVuU6XMdQwqV9WQEgn
M5y0NDEThYNkX1zE24eSXPJDECiXCuOAXGhyBr3pelL5yU085g2NVXSzQu71c3RV
+mOr+hLl3Wtq/mwyHPjG
=HfbQ
-----END PGP SIGNATURE-----
Hi Robert,

In those cases a HTTP 404 is the right response, to help Search Engines realise that such a URL doesn't exist and to show users a "Page Not Found" message. To create a nice looking 404 response for users just write a view to handle it and add the "handler404" entry to your root URLConf module (the one near the settings.py module).

Adding something like this to urls.py:

handler404 = 'views.http404_handler'

And creating that view in the corresponding views.py module:

from django.http import HttpResponseNotFound
from django.template import loader, RequestContext

def http404_handler(request):
    t = loader.get_template("404.html")
    return HttpResponseNotFound(
        t.render(RequestContext(request, {'request_path': request.path})))

Also create the template 404.html in your templates directory.


Good luck,
Daniel


On 23 Sep 2014, at 04:25, robert brook <software.by.python@gmail.com> wrote:

How is a url conf written so that if none of the useful urls are matched it will pass through to some sort of wild card regular expressions so that the view / redirection can be performed gracefully

Thanks

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f981954c-679a-4000-9e4c-11d3e6ee3e09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment