我在後端使用了Angular 4前端和Python Django。 如果我點擊詳細按鈕,我在組件如何在Django中忽略或重定向http請求?
openDetail(id:number){
this.router.navigate(['/motor/detail', {"id": id}])
}
運行openDetail
方法瀏覽器中打開的URL http://localhost:8000/motor/detail;id=21
細節成分。完善。重要的是要知道的是,我只需要id在我的詳細信息組件中與他們一起工作。
但是,如果我刷新頁面,我遇到404錯誤。 - >The current path, motor/detail;id=21, didn't match any of these.
好吧,這個也很清楚,並跳入後端。
主 - urls.py
#... some other urls...
url(r'^motor/', include('motorControll.urls')),
電機 - urls.py
url(r'^$', views.index, name="index"),
url(r'^overview/$', views.MotorMapping.as_view({'get': 'getAllData'})),
url(r'^detail/$', views.index, name="index"),
url(r'^detail/(?P<id>\d+)/$', views.MotorMapping.as_view({'get': 'getById'})),
url(r'^detail/save/$', views.MotorMapping.as_view({'post': 'save'})),
我怎麼可以忽略此調用或運行一個重定向到索引頁? 我需要這個id,因爲下一步,在加載詳細頁面之後,通過這個url http://localhost:8000/motor/detail/21
加載詳細信息,它會返回JSON和所有數據。
爲什麼你的URL中有';'。這是一個錯字嗎? –
其實不是。它是從一個角教程https://angular.io/guide/router#heroes-list-optionally-selecting-a-hero我希望我理解的內容正確:) - >滾動一點點,它在藍色方框'矩陣URL表示法' –
我建議您使用查詢參數而不是矩陣URL表示法。這是真正的休息標準,它也會容易使用,而不是角度 –