1

I was busy doing the Django tutorials and they explain how you can have url patterns which make it possible to pass information back to the functions in the view.py file. For example

urlpatterns = patterns('',
    url(r'^some_view/(?P<number>\d+)', views.some_view, name = 'some_view')

and the integer in the url slot '(?Pnumber>\d+)' is passed to the some_view function in the file views.py. Apparently the d+ stands for decimal but what should it be if I want to pass a string variable back to the some_views function.

1 Answer 1

1

You need to use this partern: (?P<anystring>.+)

urlpatterns = patterns('',
    url(r'^some_view/(?P<anystring>.+)', views.some_view, name = 'some_view')
Sign up to request clarification or add additional context in comments.

3 Comments

Be aware that this pattern will consume any URL of type some_view/... and prevent any other URL from being parsed after that like some_view/object/id. You might want to use \w+ instead.
Yep, but I just using it as example.
I'm not saying you're wrong. Just cautioning the OP to not use the example as is. :)

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.