如何在 Django 视图中进行 url 编码

kuk*_*lia 1 python django url python-3.x

在 Django 中,我想这样做

 <a href="{% url 'firstapp:create' %}?next={{ nextos|urlencode }}">
Run Code Online (Sandbox Code Playgroud)

但在我的views.py中,当我渲染页面时

return render(request, 'create' + parameter next=nextos)
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

alb*_*ick 7

我只得自己做这件事。最终得到这个解决方案

from django.utils.http import urlencode
from django.http import HttpResponseRedirect
Run Code Online (Sandbox Code Playgroud)

那么在你看来:

 return HttpResponseRedirect( reverse('firstapp:create') + '?' + urlencode({'next': nextos }))
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助!
缺口