我已經(jīng)被困在這個(gè)問(wèn)題上有一段時(shí)間了,似乎無(wú)法修復(fù)錯(cuò)誤。我已經(jīng)檢查了代碼一百次,但顯然我遺漏了一些東西。我也安裝了我的應(yīng)用程序。我使用 3 個(gè)按鈕為用戶(hù)創(chuàng)建了 CRUD 操作:詳細(xì)信息、編輯和刪除。第二個(gè) 2 完全按照應(yīng)有的方式工作,但第一個(gè)“詳細(xì)信息”給了我這個(gè)錯(cuò)誤:NoReverseMatch at /users/details/1 未找到“user_edit”的反向。“user_edit”不是有效的視圖函數(shù)或模式名稱(chēng)。我正在嘗試呈現(xiàn)user_details函數(shù),但我找不到為什么給我user_edit錯(cuò)誤消息。有人能看到我錯(cuò)過(guò)了什么嗎?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)
2 回答

犯罪嫌疑人X
TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊
您能提供項(xiàng)目文件夾中存在的 urls.py 文件嗎?我認(rèn)為問(wèn)題在于項(xiàng)目文件夾中存在的 urls.py 文件,您應(yīng)該提供“appname”和“namescape”

慕妹3242003
TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超6個(gè)贊
在urls.py
文件中,在行中
path('users/edit/<int:id>', views.user_edit, name="useredit"),
更改name="useredit"
為name="user_edit"
添加回答
舉報(bào)
0/150
提交
取消