亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

錨標記內的 django-URL 變得相對于當前頁面 django

錨標記內的 django-URL 變得相對于當前頁面 django

夢里花落0921 2023-10-10 16:20:24
urls.py    path('add_a_product_to_store/<store_id>',views.add_a_product_to_store,name='add_a_product_to_store'),    path('show_a_store/<store_id>', views.show_a_store,name='show_a_store')show_a_store.html<a href="add_a_product_to_store/5">Add a product</a>當用戶輸入ip:port/show_a_store/5. 。。。show_a_store.html顯示。但錨標記內的鏈接指向http://127.0.0.1:8000/show_a_store/add_a_product_to_store/5而不是http://127.0.0.1:8000/add_a_product_to_store/5如何讓它指向實際的 url 而不管當前頁面?
查看完整描述

3 回答

?
嗶嗶one

TA貢獻1854條經驗 獲得超8個贊

添加斜杠,如下所示


path('add_a_product_to_store/<store_id>/',views.add_a_product_to_store,name='add_a_product_to_store'),

path('show_a_store/<store_id>/', views.show_a_store,name='show_a_store')

和模板


<a href="{% url 'add_a_product_to_store' store_id=object.id %}">Add a product</a>


查看完整回答
反對 回復 2023-10-10
?
萬千封印

TA貢獻1891條經驗 獲得超3個贊

您需要使用url模板標簽

<a?href="{%?'add_a_product_to_store'?store_id=5?%}">Add?a?product</a>


查看完整回答
反對 回復 2023-10-10
?
不負相思意

TA貢獻1777條經驗 獲得超10個贊

我在html中犯了一個錯誤。使用錨標記時,<a href="foo/">表示 **ip:port/url-of-current-page/foo/... 但 <a href="/foo/">
表示如果url 開頭ip:port/foo/ 沒有,則將其視為相對 url,并將當前頁面的 url 附加到該 url 中。forward slash (/)

查看完整回答
反對 回復 2023-10-10
  • 3 回答
  • 0 關注
  • 140 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號