我正在尝试在我的班级模型中编辑班级,但是其给出的错误帮助我尝试解决此错误
找不到带有参数'('',)'的'editclasses'。尝试了1种模式:['学生/编辑类/(?P [0-9] +)/ $']
classes.html
{% for clas in clas %}
<tr>
<td>{{clas.class_name}}</td>
<td>
<a href="{% url 'editclasses' clas.pk %}" class="btn btn-outline-info btn-sm" role="button"> Edit</a>
</td>
</tr>
{% endfor %}
editclasses.html
div class="container">
<h4 class="text-center">Edit Class</h4>
<hr/>
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
{% for field in form %}
<div class="form-group row">
<label for="id_{{ field.name }}" class="col-2 col-form-label">{{ field.label }}</label>
<div class="col-10">
{{ field }}
{{ field.errors }}
</div>
</div>
{% endfor %}
<button type="submit" class="btn btn-primary" name="button">Update</button>
</form>
<br/><br/>
</div>
课程的views.py
def editclasses(request, pk):
clas = get_object_or_404(Classes, pk=pk)
if request.method == "POST":
form = ClassesForm(request.POST or None, instance=clas)
if form.is_valid():
form.save()
return redirect('home')
else:
form = ClassesForm(instance=gr)
return render(request, 'students/editclasses.html', {'form': form})
def classes(request):
clas = Classes.objects.all()
context = {'clas': clas}
return render(request, 'students/classes.html', context)
urls.py用于编辑类
path('editclasses/<int:pk>/', views.editclasses, name='editclasses'),