开发者

Seem to have a problem with returning an order.pk value with Django

(r'^search/(?P<client_id>\d+)/(?P<order_no>\d+)/test_items/$', views.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+)/$', 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.

#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.

<in开发者_高级运维put type="submit" value="Request Delivery" onclick="change_action('{% url tiptop.views.service_order2 order.pk client.pk 1 %}')"/>


From the error message it seems that client_id is empty.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜