[英]URL available in urls.py still getting 404 in Django 2
我在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 正常工作。
不知道我哪里錯了!
要在Path
使用str
您可以使用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",)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.