<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] # 簡介 在django中,通過瀏覽器去請求一個頁面時,使用視圖函數來處理這個請求的,視圖函數處理之后,要給瀏覽器返回頁面內容 創建模板文件夾 ![](https://box.kancloud.cn/5492a8095efbe94010b8eca2c40b15c1_288x296.png) 然后在setting.py中寫上模板文件的路徑 ![](https://box.kancloud.cn/75fe3173f918289d295387e07554c79b_1352x344.png) 在對應項目的views.py中寫 ~~~ from django.shortcuts import render from django.http import HttpResponse from django.template import loader, RequestContext # Create your views here. # 定義視圖函數,HttpRequest # 1. http://127.0.0.1:8000/index # 2. 進行url配置,建立url地址和視圖的對應關系 def index(request): # 使用模板文件 # 加載模板文件,模板對象 temp = loader.get_template('booktest/index.html') # 模板渲染:產生標準的html內容 res_html = temp.render({'content' : 'hello', 'list' : list(range(1,10))}) # 返回瀏覽器 return HttpResponse(res_html) ~~~ 重定向 ~~~ from django.shortcuts import render, redirect from django.http import HttpResponse, HttpResponseRedirect ~~~ ~~~ # return HttpResponseRedirect('/index') return redirect('/index') ~~~ 然后在對應模板下面創建index.html ~~~ <!doctype html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>booktest</title> </head> <body> booktest <h1>使用模板變量</h1> {{ content }} <br /> <h1>使用列表</h1><br /> {{ list }} <br /> {% for i in list %} {{ i }} <br /> {% endfor %} </body> </html> ~~~ # url傳參數 urls.php 這邊的數字正則要用()括起來 ~~~ urlpatterns = [ # 通過url函數設置url路由配置項 url(r'^index$', views.index), # 建立和視圖關聯 # 輸入書的id顯示英雄信息 url(r'^book/(\d+)$', views.detail) ] ~~~ views.php ~~~ def detail(request, bid): '''查詢圖書關聯英雄信息''' # 1. 根據bid查詢圖書信息 book = BookInfo.objects.get(id = bid) # 2. 查詢和book關聯的英雄信息 heros = book.heroinfo_set.all() # 3. 使用模板 return render(request, 'booktest/detail.html', {'book' : book, 'heros' : heros}) ~~~ detail.html ~~~ <h1>{{ book.btitle }}</h1> 英雄信息如下: <br /> <ul> {% for hero in heros %} <li>{{ hero.hname }} --- {{ hero.hcomment }}</li> {% empty %} <li>沒有英雄信息</li> {% endfor %} </ul> ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看