Here is my URLconf:
urlpatterns = patterns('',
url(r'^new_player/$', new_player, name="new_player"),
url(r'^new_player/player_added/$', player_added, name="player_added"),
url(r'^(\d+)/new_avatar/$', new_avatar, name='new_avatar' ),
url(r'^(?P<user_name>[-\w]+)/new_game/$', new_game, name='new_game' ),
url(r'^$', 'django.views.generic.list_detail.object_list', { 'queryset': Player.objects.all(),'extra_context': {'players' : Player.objects.annotate(total_amount_won=Sum('avatar__games__profit'))}}, 'stakeme_player_list'),
url(r'^(?P<real_name>[\w|\W]+)/', usernames_by_player),
url(r'^(?P<user_name>[\w|\W]+)/', avatars_by_username),
)
As written above, url(r'^(?P<real_name>[\w|\W]+)/', usernames_by_player), will display it’s associated template, but url(r'^(?P<user_name>[\w|\W]+)/', avatars_by_username), will 404.
If I reverse the order of the last two URLs, the 404 will display for usernames_by_player instead of avatars_by_username
I can see how, due to the similar URL patterns, this could cause a problem but could someone explain why and how to resolve please?
Those urls are looked up in the order you defined them. So this line
url(r'^(?P<real_name>[\w|\W]+)/', usernames_by_player)grabs all input from the request url. You should distinguish these urls like:Hope this leads into the right direction.