Darwin Tech
Darwin Tech

Reputation: 18919

Django ignore character in url parameter

Hi I have a url pattern like so:

url(
    r'^project_info/(?P<product>\w+)/$',
    'tool.views.ProjectInfo',
    name='project_info'
),

this works fine for normal strings, but if I want to capture something like 'my-product' it fails.

I have tried escaping the dash like so:

url(
    r'^project_info/(?P<product>\-\w+)/$',
    'tool.views.ProjectInfo',
    name='project_info'
),

but no joy.

Any help would be much appreciated.

Upvotes: 0

Views: 304

Answers (1)

Thomas Schw&#228;rzl
Thomas Schw&#228;rzl

Reputation: 9917

This should work for you

url(
    r'^project_info/(?P<product>[-\w]+)/$',
    'tool.views.ProjectInfo',
    name='project_info'
),

Upvotes: 6

Related Questions