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>

萬千封印
TA貢獻1891條經驗 獲得超3個贊
您需要使用url模板標簽
<a?href="{%?'add_a_product_to_store'?store_id=5?%}">Add?a?product</a>

不負相思意
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 (/)
- 3 回答
- 0 關注
- 140 瀏覽
添加回答
舉報
0/150
提交
取消