[Fixed]-Django {% url %} with non Ascii parameters

1👍

Your regex, [0-9A-Za-z._%+-]+, does not match non-ascii characters. You have to use \w instead. The URL dispatcher will set the re.UNICODE flag for compiled regexes, and this will match any alphanumerical unicode character.

You’d also want to add $ to the end of your regex to match the end of line.

url(r'^dist=(?P<district>[\w\.%+-]+)/$', views.district, name='district'),
👤knbk

Leave a comment