在 Django 中,我想這樣做 <a href="{% url 'firstapp:create' %}?next={{ nextos|urlencode }}">但在我的views.py中,當我渲染頁面時return render(request, 'create' + parameter next=nextos)有任何想法嗎?
3 回答

達令說
TA貢獻1821條經(jīng)驗 獲得超6個贊
我只得自己做這件事。最終得到這個解決方案
from django.utils.http import urlencode from django.http import HttpResponseRedirect
那么在你看來:
return HttpResponseRedirect( reverse('firstapp:create') + '?' + urlencode({'next': nextos }))
我希望這有幫助!
缺口

白衣非少年
TA貢獻1155條經(jīng)驗 獲得超0個贊
接受的答案略有不同:python 的 f 字符串表示法在這里非??勺x:
HttpResponseRedirect( f"{reverse('firstapp:create')}?{urlencode({'next': nextos })}")

慕容3067478
TA貢獻1773條經(jīng)驗 獲得超3個贊
你可以這樣做:
<a href="{% url 'firstapp:create' next=nextos %}">
這會生成 URL,無需編碼。
添加回答
舉報
0/150
提交
取消