Я новичок в Джанго. Я создал простой createview, а затем попытался аналогичным образом обновить updateview, но получил ошибку NoReverseMatch. Я попробовал много способов, предложенных онлайн, но все же они, казалось, не работали.
Это скриншот ошибки, которую я получаю NoReverseMatchError
Ниже мои файлы
urls.py
from django.contrib import admin
from django.urls import path
from django.conf.urls import url,include
from mapp import views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^$',views.AboutView.as_view(),name='about'),
url(r'^blogs/$',views.BlogsView.as_view(),name='blog'),
url(r'^project/$',views.ProjectListView.as_view(),name='project_list'),
url(r'^project/(?P<pk>\d+)/$',views.ProjectDetailView.as_view(),name='project_detail'),
url(r'^project/create/$',views.ProjectCreateView.as_view(),name='project_create'),
url(r'^project/(?P<pk>\d+)/$',views.ProjectUpdateView.as_view(),name='update'),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Views.py
from django.shortcuts import render,redirect
from django.views.generic import TemplateView,ListView,DetailView,CreateView,UpdateView
from mapp.models import Project
from mapp.forms import ProjectCreateForm,ProjectUpdateForm
# Create your views here.
class AboutView(TemplateView):
template_name='about.html'
class BlogsView(TemplateView):
template_name='blogs.html'
class ProjectListView(ListView):
model=Project
class ProjectDetailView(DetailView):
model=Project
class ProjectCreateView(CreateView):
model=Project
form_class=ProjectCreateForm
redirect_field_name='mapp/project_detail.html'
class ProjectUpdateView(UpdateView):
model=Project
form_class=ProjectUpdateForm
redirect_field_name='mapp/project_detail.html'
Project_detail.html
{% extends 'base.html'%}
{% block content %}
<h1>Project Details</h1>
<div class="container">
<h2>{{project.pname}}</h2>
<img src="{{project.pimage.url}}"></img>
<h2>{{project.ptech}}</h2>
<h2>{{project.pdetails}}</h2>
</div>
<div class="container">
<p><a href="{%url 'update' pk=self.pk %}">Update</a>
</div>
{% endblock %}
Forms.py
from django import forms
from mapp.models import Project
class ProjectCreateForm(forms.ModelForm):
class Meta:
model=Project
fields=('pname','pimage','ptech','pdetails')
class ProjectUpdateForm(forms.ModelForm):
class Meta:
model=Project
fields=('pname','pimage','ptech','pdetails')
Project_form.html
{% extends 'base.html' %}
{% block content %}
<form class="project-form" method="POST" enctype="multipart/form-data">
<div class="jumbotron">
{% csrf_token %}
{{form.as_p}}
<button type="submit" class="save btn btn-default">Save</button>
</div>
</form>
{% endblock %}