If you want the form form to submit a URL that is similar to action= "/index-5-6.html", you can use the {% url ' test1 ' param1=5 param2=6%} in the HTML template language
urls.py
From django.conf.urls import URL, includefrom mytest import viewsurlpatterns = [ url R ' ^index-(? p<param1>\d+)-(? p<param2>\d+). html ', Views.index, name= ' test1 '),]
views.py
From django.http import httpresponsefrom django.shortcuts import renderfrom django.views import ViewDef index (req, param1 , param2): return render (req, ' index.html ')
Html
<! DOCTYPE html>{% url ' test1 ' param1=5 param2=6%}" method= "POST" > <input type= "text" name= "A"/> <input type= "Submit" Name= "B" value= "Submit"/> </form> </body>
Note:
This method can only return a dead URL, regardless of what is passed through the front-end access, the URL of the form form submission is fixed. As shown in the example above, the URL submitted is always action= "/index-5-6.html"
If you want to return the same URL as the Request.path_info effect, you can use reverse.
urls.py
From django.conf.urls import urlfrom mytest Import viewsurlpatterns = [ url R ' ^index-(? p<param1>\d+)-(? p<param2>\d+). html ', Views.index, name= ' test1 '),]
views.py
From django.http import httpresponsefrom django.shortcuts import renderdef index (req, param1, param2): from Django.urls Import Reverse reverse (' test1 ', kwargs={' param1 ': param1, ' param2 ': param2}) Return render (req, ' index.html ', {' URL1 ': X,})
Html
<! DOCTYPE html>{{URL1}}" method= "POST" > <input type= " Text "name=" A "/> <input type=" Submit "Name=" B "value=" Submit "/> </form></body>
Django--url (template language {% url ' test1 ' param1=5 param2=6%})