2011-02-24 55 views
0
(r'^search/(?P<client_id>\d+)/(?P<order_no>\d+)/test_items/$', views.test_items), 

我想要一個鏈接,可以去這個網址views.service_order2,不幸的是,我不斷收到NoReverseMatch錯誤。似乎有問題與Django返回order.pk值

(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 %}')"/> 
+0

您是否嘗試過在兩個視圖中打印'order'值的微不足道的東西? –

+0

@Michal是的,我有他們在兩個視圖工作。 – Shehzad009

+0

'{{order.pk}}'產生任何東西嗎? – czarchaic

回答

0

從錯誤消息看來,client_id似乎是空的。