Basically, my goal is to redirect the user to the view that renders index.html
if nothing from URLConf matched the requested url. Then, on the clientside, I would manage routing as appropriate or show 404 page.
So basically, the question is,
how to implement this redirecting in Django? I have tried this:
url(r'^(.*)$', views.index),
...some other urls
...and not surprisingly, (.*)
means that ALL urls are redirected to index.html, no matter if there it matches any other URL or not. So should I just place this in the very end of the url list? I have a feeling that I should use some sort of middleware, or maybe Django has a native way to address this issue?
- An umpleasant side-effect of this would be for users of my rest app. Each time they all an invalid URL, they would get HTML (that would in effect be the HTML for home.html) instead of json or 404 error. Well, nothing ugly about index.html code, and yet it sounds like a bad idea. So would I separate this logic so that the users of REST app get 404 error instead of being redirected to index.html? This is much about coding patterns, not Django itself. And yet I would really appreciate any comments on this as well :)