使用 Django 返回 order.pk 值似乎有问题
(r'^search/(?P<client_id>\d+)/(?P<order_no>\d+)/test_items/$', views.test_items),
我想要一个可以转到此网址views.service_order2 的链接,不幸的是,我不断收到NoReverseMatch 错误。
(r'^quote/service_order/(?P<client_id>\d+)/(?P<order_no>\d+)/(?P<request_type>\d+)/$', views.service_order2),
Caught NoReverseMatch while rendering: Reverse for 'tiptop.views.service_order2' with arguments '('', 17L, 1)' and keyword arguments '{}' not found
问题好像是我的订单没有pk值。不过,我已经使用 test_items 视图完成了相同的过程,效果很好。为什么在我的一个视图中我可以返回 order.pk 值,但在另一个视图(service_order2 视图)中我不能返回这是问题。
#views.py
def service_order2(request, client_id = 0, order_no = 0, request_type = 1):
# A lot of code
order=request.session['order']
return render_to_response('service_step1__2nd.html', {'contacts':contacts, 'addresses':addresses, 'title':title, 'service_list':service_list, 'date_type':date_type, 'address_type':address_type, 'order':order}, context_instance = RequestContext(request))
def test_items(request, client_id = 0, order_no= 0):
client = None
items = None
try:
client = models.Client.objects.get(pk = client_id)
items = client.storageitem_set.all()
order=request.session['order']
except:
return HttpResponse(reverse(return_clients))
return render_to_response('test.html', {'items':items, 'client':client, 'order':order}, context_instance = RequestContext(request))
在我的名为 test.html 的模板中,我在里面写入了模板标记链接。
<input type="submit" value="Request Delivery" onclick="change_action('{% url tiptop.views.service_order2 order.pk client.pk 1 %}')"/>
(r'^search/(?P<client_id>\d+)/(?P<order_no>\d+)/test_items/
I want a link that can go to this url views.service_order2, Unfortunately, I keep getting a NoReverseMatch error.
(r'^quote/service_order/(?P<client_id>\d+)/(?P<order_no>\d+)/(?P<request_type>\d+)/
The problem seems that my order does not have a pk value. However I have done the same procedure with test_items view and that worked out fine. Why is that in one of my views I can return an order.pk value, but in another (service_order2 view) I can't is the question.
#views.py
def service_order2(request, client_id = 0, order_no = 0, request_type = 1):
# A lot of code
order=request.session['order']
return render_to_response('service_step1__2nd.html', {'contacts':contacts, 'addresses':addresses, 'title':title, 'service_list':service_list, 'date_type':date_type, 'address_type':address_type, 'order':order}, context_instance = RequestContext(request))
def test_items(request, client_id = 0, order_no= 0):
client = None
items = None
try:
client = models.Client.objects.get(pk = client_id)
items = client.storageitem_set.all()
order=request.session['order']
except:
return HttpResponse(reverse(return_clients))
return render_to_response('test.html', {'items':items, 'client':client, 'order':order}, context_instance = RequestContext(request))
In my template called test.html, I have this the template tag link written inside.
<input type="submit" value="Request Delivery" onclick="change_action('{% url tiptop.views.service_order2 order.pk client.pk 1 %}')"/>
, views.test_items),
I want a link that can go to this url views.service_order2, Unfortunately, I keep getting a NoReverseMatch error.
The problem seems that my order does not have a pk value. However I have done the same procedure with test_items view and that worked out fine. Why is that in one of my views I can return an order.pk value, but in another (service_order2 view) I can't is the question.
In my template called test.html, I have this the template tag link written inside.
, views.service_order2),
Caught NoReverseMatch while rendering: Reverse for 'tiptop.views.service_order2' with arguments '('', 17L, 1)' and keyword arguments '{}' not found
The problem seems that my order does not have a pk value. However I have done the same procedure with test_items view and that worked out fine. Why is that in one of my views I can return an order.pk value, but in another (service_order2 view) I can't is the question.
In my template called test.html, I have this the template tag link written inside.
, views.test_items),I want a link that can go to this url views.service_order2, Unfortunately, I keep getting a NoReverseMatch error.
The problem seems that my order does not have a pk value. However I have done the same procedure with test_items view and that worked out fine. Why is that in one of my views I can return an order.pk value, but in another (service_order2 view) I can't is the question.
In my template called test.html, I have this the template tag link written inside.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从错误消息来看,client_id 似乎为空。
From the error message it seems that client_id is empty.