I am trying to get a url structure like this.
http://example.com/blog/1/title-name-goes-here
My main urls file has this line, among others.
url(r'^blog/', include('blog.urls')),
in my blog.urls I have
urlpatterns = patterns('',
(r'', 'blog.views.index'),
(r'^(?P<entry_id>\d+)/(?P<slug>[a-zA-Z0-9_.-]+)/$', 'blog.views.entry'),
)
My problem is when I visit /blog/1/some-title I get the index view called, not the entry view method. It also doesn’t matter what order the routes are in either.
I think the regex is wrong. I am still not good with them.
try:
Notice the carat and dollar sign in the lower pattern which signifies an empty pattern. You should (generally) put your patterns in order of how many groups then need to match e.g. /id/slug/title/ above /id/slug/ above /id/ as the URLconf chooses the first match possible. You can use RegexPal to test your patterns online which is handy
I also changed the slug to a simpler slug pattern using \w (word, number underscore – I’m not sure if you specifically want to match dots in slugs?)