Monday, 15 April 2013

python - Regex match string beginning with ?code= -



python - Regex match string beginning with ?code= -

i'm using python , django match urls site. need match url looks this: /company/code/?code=34k3593d39k

the part after ?code= combination of letters , numbers, , length.

i've tried far:

r'^company/code/(.+)/$' r'^company/code/(\w+)/$' r'^company/code/(\d+)/$' r'^company/code/(.*)/$'

but far none catching expression. ideas? thanks

code=34k3593d39k get parameter , don't need define pattern in url pattern. can access using request.get.get('code') under view. pattern should just:

r'^company/code/$'

usage, accessing parameter:

def my_view(request): code = request.get.get('code') print code

check documentation:

the urlconf searches against requested url, normal python string. not include or post parameters, or domain name.

python regex django django-views django-urls

No comments:

Post a Comment