In a django app, I need to create twitter user profile urls with following structure like:
example.com/<username>
example.com/<username>/friends
example.com/<username>/blog
example.com/<username>/some-page
example.com/<username>/some-other-page
My urls.py:
urlpatterns = patterns('profiles.views',
url(r'^(?P<account_name>[a-zA-Z0-0_.-]+)/$', 'show_profile', name='profiles_show_profile'),
url(r'^(?P<account_name>[a-zA-Z0-0_.-]+)/friends/$', 'show_friends', name='profiles_show_blog'),
url(r'^(?P<account_name>[a-zA-Z0-0_.-]+)/blog/$', 'show_blog', name='profiles_show_blog'),
)
My first problem is that while example.com/<username>
works fine example.com/<username>/any-other-page
does not. They all end up at show_profile
view instead of their own view.
Note: Everything works fine if I make urls change the url structure to example.com/user/<username>
What am I doing wrong here? Please advise.
Secondly, I would like guidance on django best practices(pitfalls, gotchas etc) in dealing with url schemes where first part is itself is variable.
Thanks