Python ReverseMatch适用于jsonResponse,但不适用于render
我有一个新页面,其中包含:Python ReverseMatch适用于jsonResponse,但不适用于render,python,django,url,Python,Django,Url,我有一个新页面,其中包含: def person(request, galid): bunch of stuff context = { blah blah } # return JsonResponse(context) return render(request, 'pops/person.html', context) 使用url.py urlpatterns = [ path('', views.index, name=
def person(request, galid):
bunch of stuff
context = { blah blah }
# return JsonResponse(context)
return render(request, 'pops/person.html', context)
使用url.py
urlpatterns = [
path('', views.index, name='index'),
path('<slug:galid>' , views.person, name="person")
]
如果真的没有反向匹配,jsonResponse如何工作?这里发生了什么事?谢谢
令人不快的href调用是:
href="{% url 'pops:person' id %}"
其中,
id
是十六进制字符串。这是合乎逻辑的,因为JSON响应中没有反向url。Pelase在person.html
模板中显示有问题的{%url…%}
标记。您好@WillemVanOnsem我刚刚编辑了问题描述。您的上下文是否包含id
键?是否设置为整数?或者它是None
/空字符串?@WillemVanOnsem是,它被设置为十六进制字符串。我使用了{%for id,person in dict.items%},其中每个案例的id都是十六进制字符串。@WillemVanOnsem person中的上下文不包含id键。明白了,成功了!
href="{% url 'pops:person' id %}"