Mistake appeared when I added url to another app. I added
<a class="navbar-brand" href="{% url 'posts:listofposts' %}">Home</a>
My root.urls:
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'),
]
and my view in 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)
And I got the next mistake
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>
Everything worked fine untill I added url link to another app. If I delete url link to another view everithing will be okay. Thx a lot if you help.