Возникла проблема с работой кода , при попытке создать кнопки для удаления и редактирования новости на сайте возникает ошибка (На скриншоте ниже) . Где допустил ошибку не понимаю , с html работаю впервые в жизни .
views.py
from django.shortcuts import render , redirect
from .models import Artiles
from .forms import ArtilesForm
from django.views.generic import DetailView, UpdateView, DeleteView
def news_home(request):
news = Artiles.objects.order_by('date')
return render(request, 'news/newshome.html',{'news':news})
class NewsUpdateView(UpdateView):
model = Artiles
template_name = 'news/create.html'
form_class = ArtilesForm
class NewsDetailView(DetailView):
model = Artiles
template_name = 'news/details_view.html'
class NewsDeleteView(DeleteView):
model = Artiles
template_name = 'news/news_delete.html'
success_url = '/news/'
def create(request):
error = ''
if request.method == "POST":
form = ArtilesForm(request.POST)
if form.is_valid():
form.save()
return redirect('home')
else:
error = 'Форма не вірна'
form = ArtilesForm()
data = {
'form': form,
'error': error
}
return render(request, 'news/create.html', data)
urls.py
from django.urls import path
from . import views
urlpatterns = [
path("", views.news_home, name='news_home'),
path("create", views.create, name='create'),
path('<int:pk>', views.NewsDetailView.as_view(), name='news_detail'),
path('<int:pk>/update', views.NewsUpdateView.as_view(), name='news_update'),
path("<int:pk>/delete", views.NewsDeleteView.as_view(), name='news_delete'),
]
details_view.html
{% extends 'main/layout.html' %}
{% block title %}{{article.title}}{% endblock %}
{% block content %}
<div class="features">
<h1>{{ article.title }}</h1>
<p>{{ article.date }}</p>
<p>{{ article.full_text }}</p>
<a href="url 'news_delete' article.id" class="btn btn-new">Видалити</a>
<a href="url 'news_update' article.id" class="btn btn-new">Редагувати</a>
</div>
{% endblock %}
get_absolute_url
def get_absolute_url(self):
return f'/news/{self.id}'