首页 > 解决方案 > 如何在 django 模板语言的 url 中发送两个参数?

问题描述

{% url 'start' commission.id applie.id %}

像上面的代码一样,我正在尝试发送两个模型 ID,但我不知道它的正确结构。上面的代码不起作用。

path('start/<int:post_id>', views.start, name="start"),

def start(request,post_id):

如果我得到两个括号,我应该如何修改上面的 url 并查看代码?

标签: django

解决方案


试着走这条路。。

在 urls.py 中——

path('profile/<name> <email>', views.profile, name='profile'),
#As path have space, it will take %20 there, 
#you can change it accordingly. best to use '-' instead of space
#http://example.com/profile/myname%20myemail@example.com

在链接中——

href="{% url 'profile' name='myname' email='myemail@example.com' %}"

在views.py中——

@login_required(login_url="login")
def profile(request, name, email):
   return render(request, "profile.html", {'name': name, 'email':email})

推荐阅读