Use Django url template tag with special characters

I use the django url tag to go from one view to another:

<a href = {% url wiki_view item %}>Read more here</a>

For most β€œitems” this works fine. But I have a "subject" with / character: Sci-Fi / Fantasy. In this case, I get an error

Caught NoReverseMatch on rendering: Reverse for 'wiki_view' with arguments' (u'Sci-fi / Fantasy ',)' and keyword arguments' {} 'not found.

My urls.py is defined as such:

url(r'^wiki/page/(?P<page_title>[^/]*)/$', views.wiki_view, name = 'wiki_view'),

Is there a way to work with the "/" character this way?

+3
source share
3 answers

urlencode, , - , , / . ( dev ), :

item|urlencode:""

Django docs.

+2

Djanog slugify , URL-. URL-, .

from django.template.defaultfilters import slugify
0

Source: https://habr.com/ru/post/1776134/


All Articles