我已经被困在这个问题上有一段时间了,似乎无法修复错误。我已经检查了代码一百次,但显然我遗漏了一些东西。我也安装了我的应用程序。我使用 3 个按钮为用户创建了 CRUD 操作:详细信息、编辑和删除。第二个 2 完全按照应有的方式工作,但第一个“详细信息”给了我这个错误:NoReverseMatch at /users/details/1 未找到“user_edit”的反向。“user_edit”不是有效的视图函数或模式名称。我正在尝试呈现user_details函数,但我找不到为什么给我user_edit错误消息。有人能看到我错过了什么吗?views.pydef user_details(request, id=None): context = {} context['user'] = get_object_or_404(User, id=id) return render(request, 'userdetails.html', context)def user_add(request): context = {} if request.method == 'POST': u = user_form = UserForm(request.POST) context['user_form'] = user_form if user_form.is_valid(): user_form.save() return HttpResponseRedirect(reverse('feedback:users')) else: return render(request, 'useradd.html', context) else: user_form = UserForm() context['user_form'] = user_form return render(request, 'useradd.html', context)def user_edit(request, id=None): context = {} user = get_object_or_404(User, id=id) if request.method == 'POST': user_form = UserForm(request.POST, instance=user) context['user_form'] = user_form if user_form.is_valid(): user_form.save() return HttpResponseRedirect(reverse('feedback:users')) else: return render(request, 'useredit.html', context) else: user_form = UserForm(instance=user) context['user_form'] = user_form return render(request, 'useredit.html', context)def user_delete(request, id=None): context = {} return render(request, 'userdelete.html', context)
添加回答
举报
0/150
提交
取消