0
別のアプリにURLを追加すると、間違いが表示されます。'NoReverseMatch at' django mistake
urlpatterns = [
url(r'^', include('posts.urls', namespace= 'posts'))
]
posts.urls:
urlpatterns = [
url(r'^create/',
create_post ,
name='create_post'),
url(r'^(?P<slug>[-\w]+)/edit/$',
update_post,
name = 'update_post'),
url(r'^category/(?P<slug>[-\w]+)/$',
category,
name='category'),
url(r'^(?P<slug>[-\w]+)/$',
detail,
name = 'detail'),
url(r'^$',
listofposts ,
name='listofposts'),
]
とpost.viewsでの私の見解:
def listofposts(request, category_slug = None):
html = 'base.html'
Category_all = Category.objects.all()
query_set_list = Post.objects.all()
query = request.GET.get("q")
if query:
query_set_list = query_set_list.filter(title__icontains=query)
if category_slug:
category = get_object_or_404(Category, slug=category_slug)
products = Post.filter(category=category)
context = {
"title" : 'Записки',
"list" : query_set_list,
'category_all' : Category_all,
}
return render(request, html, context)
def detail(request, slug):
Category_all = Category.objects.all()
html = 'post_detail.html'
query_set = Post.objects.all()
instance = get_object_or_404(Post, slug = slug)
context = {
"title" : instance.title,
"instance" : instance,
"list": query_set,
'category_all' : Category_all,
}
return render(request, html, context)
そして私 私は
<a class="navbar-brand" href="{% url 'posts:listofposts' %}">Home</a>
マイroot.urlsを追加しました次の間違いを持った
Exception Value:
Reverse for 'detail' not found. 'detail' is not a valid view function or pattern name.
<a href="{{ x.get_absolute_url }}"><p>{{ x.title }}</p></a>
別のアプリにURLリンクを追加するまですべてうまくいきました。私は別のビューへのリンクを削除する場合、everithingは大丈夫です。もしあなたが助けてくれたら、たくさんのThx。
あなたがエラーの原因となっている 'get_absolute_url'方法を示していません。 \t \t戻り逆( '詳細'、 \t \t \t \t \t引数= [STR(self.slug)] \t \t \t \t \t) – Alasdair
はDEF(自己)はget_absolute_url大いに感謝する!!! – question1