[Answer]-Incorrect Django URL pattern match for 2 views with the same URL structure?

1👍

Both urls use the same regex. I removed the group names and get:

url(r'^(.+)-(.+)-(.+)/$', songs.dj_song, name='dj_song'),
url(r'^(.+)-(.+)-(.+)/$', songs.trending_song, name='trending_song'),

Of course django uses the first match.

You should use different urls for different views. For example add the prefix to the second url:

url(r'^trending/(?P<song_name>.+)-(?P<artist_slug>.+)-(?P<song_id>.+)/$',
                                  songs.trending_song, name='trending_song'),

Leave a comment