Answer the question
In order to leave comments, you need to log in
Why does a 404 error occur when going to a page with a form?
Good afternoon!
I can't figure out why when clicking on a link to a page with a form, a 404 error pops up with the following content:
Request Method: GET
Request URL: http://localhost:8000/news/add-news/
Raised by: news.views.ViewNews
<li class="nav-item"><a class="nav-link" href="{%url 'add_news'%}">Добавить новость</a></li>
path('news/add-news/', CreateNews.as_view(), name='add_news')
class CreateNews(CreateView):
form_class = NewsForm
template_name = 'news/add_news.html'
def get_absolute_url(self):
return reverse('view_news', kwargs={'slug': self.slug})
class ViewNews(DetailView):
model = News
context_object_name = 'news_item'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['unwanted_link'] = News.objects.get(slug=self.kwargs['slug']).category.pk
return context
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question