Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django url pattern for %20

Tags:

In Django what is the url pattern I need to use to handle urlencode characters such as %20

I am using (?P<name>[\w]+) but this only handles alphanumeric characters so % is causing an error

like image 950
John Avatar asked Sep 09 '10 09:09

John


People also ask

What is URL pattern in Django?

In Django, views are Python functions which take a URL request as parameter and return an HTTP response or throw an exception like 404. Each view needs to be mapped to a corresponding URL pattern. This is done via a Python module called URLConf(URL configuration) Let the project name be myProject.

Does the order of the URL patterns matter in Django?

Exact regular expressions, where url order doesn't matter. Notice the regular expressions in listing 2-3 end with the $ character. This is the regular expression symbol for end of line, which means the regular expression urls only match an exact pattern.

How do I pass URL parameters in Django?

Django URL pass parameter to view You can pass a URL parameter from the URL to a view using a path converter. Then “products” will be the URL endpoint. A path converter defines which type of data will a parameter store. You can compare path converters with data types.

What is name in Django URLs?

Django offers a way to name urls so it's easy to reference them in view methods and templates. The most basic technique to name Django urls is to add the name attribute to url definitions in urls.py .


2 Answers

I was able to make it work using the configuration given below. Check if it will suit your needs.

(?P<name>[\w|\W]+) 
like image 53
Manoj Govindan Avatar answered Oct 08 '22 01:10

Manoj Govindan


If you only want to allow space:

(?P<name>[\w\ ]+) 
like image 40
chall Avatar answered Oct 08 '22 03:10

chall