2013-07-25 98 views
0

我試圖用Django開發一個博客腳本。但是,當我想顯示帖子鏈接時,我收到NoReverseMatch錯誤。Django NoReverseMatch錯誤

我views.py

# -*- coding: utf-8 -*- 

# Create your views here. 

from .models import Yazi, Yorum, Kategori 
from django.http import HttpResponse, Http404 
from django.shortcuts import render_to_response 
from django.template import RequestContext, loader 
from django.contrib.sites.models import Site 

def Home(request): 
    try: 
     posts = Yazi.objects.filter(yayinlanmis=True).order_by('-yayinlanma_tarihi') 
    except Yazi.DoesNotExist: 
     raise Http404 
    site = Site.objects.get_current() 

    c = RequestContext(request,{ 
     'posts':posts, 
     'site':site 
     }) 
    return render_to_response('Penguencik_Yazilar/yazi_list.html', c) 

def Detail(request, slug): 
    post = Yazi.objects.get(slug=slug) 
    site = Site.objects.get_current() 

    c= RequestContext(request,{ 
     'posts':post, 
     'site':site 
     }) 
    return render_to_response('Penguencik_Yazilar/yazi_detail.html',c) 

Urls.py在應用程序文件夾。

from django.conf.urls import patterns, url 
import views 

urlpatterns = patterns('', 
    url(r'^$', views.Home,name='index'), 
    url(r'^/makale/(?P<slug>[0-9A-Za-z._%+-]+)$', views.Detail,name='detail'), 
) 

Urls.py項目文件夾

from django.conf.urls import patterns, include, url 

# Uncomment the next two lines to enable the admin: 
from django.contrib import admin 
admin.autodiscover() 

urlpatterns = patterns('', 
    url(r'^$', include('Penguencik_Yazilar.urls',namespace='blog')), 
    url(r'^admin/doc/', include('django.contrib.admindocs.urls')), 
    url(r'^admin/', include(admin.site.urls)), 
) 

而且模板代碼英寸我究竟做錯了什麼?因爲你的觀點期望在這裏(?P<slug>[0-9A-Za-z._%+-]+)slug關鍵字

<a href="{% url 'blog:detail' slug=yazi.slug %}">Read</a> 

{% load url from future %} 
... 
<a href="{% url 'blog:detail' yazi.slug %}">Read</a> 

Error

回答

0

試圖改變這一點:

<a href="{% url 'blog:detail' yazi.slug %}">Read</a> 

來。

+0

http://i.imgur.com/iO1PMbn.png不工作。 –

+1

@ user2091423,如果你在這裏刪除'$'urlconf:'url(r'^',include('Penguencik_Yazilar.urls',namespace ='blog'))'和這裏'url(r'^ makale/(?P [0-9A-Za-z ._%+ - ] +)$',views.Detail,name ='detail'),'刪除第一個斜槓? – xelblch

+0

現在工作,但URL中沒有地址。只是'Read'但我想'Read' –