zoukankan      html  css  js  c++  java
  • django -- url (模版语言{{ request.path_info }})

    在django的模版语言中中可以使用   {{ request.path_info }} 帮助生成url。

    urls.py

    from django.conf.urls import url, include
    from mytest import views
    
    urlpatterns = [
        url(r'^index/', views.index, name='mysite'),
    ]
    

    views.py

    from django.http import HttpResponse
    from django.shortcuts import render
    from django.views import View
    
    
    
    def index(req):
        return render(req, 'index.html')
    

    html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>index</title>
    </head>
    <body>
        <form action="{{ request.path_info }}" method="post">
            <input type="text" name="A" />
            <input type="submit" name="b" value="提交" />
        </form>
    </body>
    </html>
    

    注意上面的模版语言用法,效果如下:

    这个用法和之前讲的 url 的name 的目的差不多:即当修改rul时,不用在html中再修改一次。

  • 相关阅读:
    codeforces 980A Links and Pearls
    zoj 3640 Help Me Escape
    sgu 495 Kids and Prizes
    poj 3071 Football
    hdu 3853 LOOPS
    hdu 4035 Maze
    hdu 4405 Aeroplane chess
    poj 2096 Collecting Bugs
    scu 4444 Travel
    zoj 3870 Team Formation
  • 原文地址:https://www.cnblogs.com/wumingxiaoyao/p/6524173.html
Copyright © 2011-2022 走看看