程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Django URL parameter transmission method

編輯:Python

There are two ways :

Only a small difference is recorded here

1, How parameters are passed

path('/abc/<int:id>/', views.abc, name='abc')
This needs to be passed id For the corresponding view
def abc(request, id):
pass
*** In this function abc Inside ,id It can be used directly ***, Don't need to use GET.get, perhaps POST.get Way to obtain , Just use it directly
reception HTML It is written in :
Such as : <a href="{% url 'bee:index_bee' bee.id %}">{
{
 bee.name }}</a>
Be careful url The command is followed by the function to be executed , Then there is the parameter ,

2, How to query strings

 How to query strings
You don't have to be here path It's equipped with , But it needs to be used in the view function POST.get, perhaps GET.get To get the passed parameters
path('abc/', views.abc, name='abc')
def abc(request):
id = request.GET.get('id') This one at the back 'id' It's on the front end HTML Page corresponding
...
The front desk HTML The page also needs to put that id Pass it to the backstage
<input name='id'>

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved