使用 Django 返回 order.pk 值似乎有问题

发布于 2024-10-19 00:43:57 字数 1697 浏览 0 评论 0原文

(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

下雨或天晴 2024-10-26 00:43:57

从错误消息来看,client_id 似乎为空。

From the error message it seems that client_id is empty.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文