2

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

2
  • The 0-0 in your regex is odd: I think you mean 0-9, though that isn't your problem. Commented Sep 12, 2010 at 12:28
  • Yes, Was a typo in my code. Fixed that. Thanks. Commented Sep 12, 2010 at 12:37

1 Answer 1

2

I don't see why your URLs aren't working. You can try moving the first pattern to the end, so that other patterns have a chance to match first. The problem you're describing sounds like example.com/user/any-page, the pattern is matching "user/any-page" as the account name. The regex you show wouldn't do that, but maybe your actual code is slightly different?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.