为什么我的代码显示此错误,因为我的整个代码是正确的?
“list”对象没有属性“_meta”
views.py
from django.shortcuts import render, redirect, get_list_or_404
from .models import Task
from .forms import TaskForm
def update_task(request, pk):
up_task = get_list_or_404(Task, id=pk)
if request.method == 'POST':
up_form = TaskForm(request.POST, instance=up_task)
if up_form.is_valid():
up_form.save()
return redirect('tasks')
else:
up_form = TaskForm(instance=up_task)
context = {
'update_task_form': up_form
}
return render(request, 'task/update_task.html', context)
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.tasks, name='tasks'),
path('task/<str:pk>/update/', views.update_task, name='update_task'),
]
浮云间
相关分类