2016-02-01 49 views
2

search.html是在哪裏顯示搜索結果列表中,但是當我點擊「搜索」按鈕,它讓我看到一個錯誤頁面「反向未找到」的頁面。我看到了同樣的問題在這裏,但代碼是不同的,所以我沒有找到我的問題的解決方案。反向沒有找到,Django的,第一次

def search(request): 
if 'q' in request.GET and request.GET['q']: 
    q = request.GET['q'] 
    words = word.objects.filter(title__icontains = q) 
    return render_to_response('dictionary/search.html', 
     {'words': words, 'query': q }) 
else: 
    return HttpResponse('Please submit a search term.') 


def worder(request, word_id): 
    showword = get_object_or_404(word, id = word_id) 
    return render(request, 'dictionary/worder.html', {'showword': showword}) 

網址:

urlpatterns = [ 
url(r'^$', Dictionary.views.home, name='home'), 
url(r'^about/$', Dictionary.views.about, name='about'), 
url(r'^search/$', Dictionary.views.search, name='search'), 
url(r'^worder/(?P<word_id>[0-9]+)/$', Dictionary.views.worder, name='worder')] 

沒有與{% url 'worder' word_id %}一個問題:

<li class="listofwords"><a class="foundword" href="{% url 'worder' word_id %}">{{ word.title }}</a></li> 

回答

3

您使用的是可變word_id不存在。您應該使用word.id這是你的物品詞的ID而不是:

<li class="listofwords"><a class="foundword" href="{% url 'worder' word.id %}">{{ word.title }}</a></li> 
+0

OMG!非常感謝,王上!我花了整整一天的時間尋找問題的解決方案! – Bootuz