python - urls.py 中可用的 URL 在 Django 2 中仍然得到 404
问题描述
我写了一个函数views.py
如下
def removeinvoices(request,invoiceID,creatorID,deletorid,typeofchange):
form = invoicestorageForm()
form.invoiceid = invoiceID
form.creatorid = creatorID
form.deletorid = deletorid
form.typeofchange = typeofchange
form.save()
thatInvoice = taxInvoice.objects.filter(invoiceid=invoiceID).first()
thatInvoice.delete()
messages.success(request, "Invoice ID "+ invoiceID +" removed Successfully !")
return redirect("vieweinvoices")
并写urls.py
如下:
path("removeinvoices/<int:invoiceID>/<int:creatorID/><int:deletorid>/<str:typeofchange>", views.removeinvoices, name="removeinvoices",)
而且我在JS中动态生成href,我能够正确地获取所有变量,但是当我点击href时 仍然说404错误
我可以很好地处理图片中提到的所有其他 URL。
不知道我哪里错了!
解决方案
要使用str
,Path
您可以使用re_path()
urls.py 使用re_path()
re_path(r"^removeinvoices/(?P<invoiceID>\d+)/(?P<creatorID>\d+)/(?P<deletorid>\d+)/(?P<typeofchange>\w+)/$", views.removeinvoices, name="removeinvoices",)
网址: http: //127.0.0.1 :9091/5/1/1/delete/
此外,在您的网址中,您/
在<int:creatorID/><int:deletorid>
.
改变:
path("removeinvoices/<int:invoiceID>/<int:creatorID/><int:deletorid>/<str:typeofchange>", views.removeinvoices, name="removeinvoices",)
至:
path("removeinvoices/<int:invoiceID>/<int:creatorID>/<int:deletorid>/<str:typeofchange>", views.removeinvoices, name="removeinvoices",)
推荐阅读
- arrays - 如何在 ruby 中加入两个表哈希
- macos - 将 Cocoa 实用程序应用程序拆分为辅助二进制文件 + 主应用程序二进制文件的利弊?
- android - 如何像图像中一样为 BottomNavigationBar 设置动画?
- java - 如何获取 ArrayList 的内容以在 JavaFX GUI 中显示
- pine-script - Tradingview 的 RSI 失败 Swing Pine 脚本问题
- node.js - npm start 不起作用。我什么都试过了。我很困惑
- javascript - 在函数中引导数据切换模式内容
- regex - 如何从记事本++上以特定单词开头的行中删除文字符号字符?
- spring-boot - 使用属性文件中配置的端点在运行时添加骆驼路线
- c# - unity登录html网页