How Do I Pass Variables In Django Through The Url?
I am trying to pass a few variables but I am having some trouble and specifically have 3 questions. How do I encode the url string to take into account the special characters in th
Solution 1:
Pass these variables as it is to template, there use url, before sending to template just do this in view.
View.py
related = urllib.quote(related, safe='')
template
<ahref="{% url 'path.to.video_player' author video related %}" ><imgsrc="img.png" ></a>
Url.py
url(r'^partner/(?P<author>[-\w]+)/(?P<video>\w+)/(?P<related>\w+)/$', 'video_player'),
EDIT
If you want to go without related parameter, or if there is doubt video can also be None then just do this in your view:
defvideo_player(request, author, video=None, related=None):
now you can use the url by
<ahref="{% url 'path.to.video_player' author video %}" ><imgsrc="img.png" ></a>
Solution 2:
in newer versions of python you could simply just type: Example:
path('<int:id>/delete/', delete_view, name = 'delete'),
Post a Comment for "How Do I Pass Variables In Django Through The Url?"