Category: English

Date:

If you were to use an unicode character in your URL that you request, you would probably face a URL matching error. Because urls.py file supports ASCII URLs by default. If you specify patterns like [a-z] or w as regular expression content, the unicode characters like ‘ö wont get matched with this regular expression. So, you have to first specify that matching will be unicode and secondly write all the letters individually in the matching range. Below is a partial urls.py file:

urlpatterns = patterns('search.pathsearch.views',
     (u'^$', 'index'),
     (u'^(?P<version>[-0-9A-Za-z]+)/$', 'index'),
     (u'^(?P<version>[-0-9A-Za-z]+)/package/(?P<package_name>[-_.0-9A-Za-zıİğĞüÜşŞöÖçÇ ]+)/$', 'list_package_contents'),
)

Instead of this hard coded solution, you can accept all the characters and then filtrate the ones you want to really accept as you can see here. But you have to be careful and filtrate carefully when using this method. Other warning will be that older versions of Python and Django can cause problems in matching unicode characters.


Share: FacebookGoogle+Email


Receive notification on my new posts

* required
Languages*   
* Different contents, not direct translation. You may choose both if you wish.
comments powered by Disqus