0

So basically I want to allow the user to go to mydomain.com/username and I have it working by adding this to the end of urlpatterns

(r'(?i)(?P<username>\w+)/$',user),

A potential issue I see arising is when a user has a username that matches with another pattern specified above. As unlikely as that could be, it's an edge case I want to catch and handle. I'm not sure what the best way to deal with it would be.

In forms.py, I have a custom username field that checks if the username is taken and that I can add other checks to. Would there be a way to basically add all the urls in urlpatterns to that list? Some way that it could automatically be changed as I add more, or would I have to hardcode them in?

Jared Joke
  • 1,226
  • 2
  • 18
  • 29
  • Have you actually tried to see what would happen if you had a username that would collide with any pattern defined _before_ the username one? – Maciej Gol Oct 14 '13 at 20:07
  • It would just go to whatever view matched happened to match mydomain.com/username – Jared Joke Oct 14 '13 at 20:38
  • I guess it would go to the first url pattern that has matched, so in this cause it would be the correct url, not the colliding one. – Maciej Gol Oct 14 '13 at 20:44
  • So there's no way to programmatically check urls? If not I might just give up on this... – Jared Joke Oct 15 '13 at 00:00
  • What I meant is that, considering your urlpatterns looks like this: `(r'my_url/', view1), (r'my_url2/', view2), (r'(?i)(?P\w+)/$',user),` then both _my_url_ and _my_url2_ will be matched __before__ your username url and in case of positive match, no further processing is done. So, in other words, if you put that url at the end of your `urlpatterns`, it will act as a url that will be matched if all other fail. – Maciej Gol Oct 15 '13 at 08:00

0 Answers0