<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>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC=1,5] >[success] # ForeignKey -- 一對多 ![](https://box.kancloud.cn/757c77f50af2a5980038a2e442fcf4e5_506x189.png) >[success] # 案例 >[danger] ##### models.py 編寫 ~~~ from django.db import models # Create your models here. class Book(models.Model): name = models.CharField(max_length=32) price = models.IntegerField() pub_data = models.DateField(auto_now_add=True) publish = models.ForeignKey('Publish') class Publish(models.Model): name = models.CharField(max_length=32) city = models.CharField(max_length=32) ~~~ >[danger] ##### views.py * get 請求通過查詢Publish數據內容,展示select 下拉展示數據 * post 請求進行數據保存 * person 函數,用來展示數據 ~~~ from django.shortcuts import render,redirect from . import models # Create your views here. def index(request): if request.method == "GET": obj_publish = models.Publish.objects.all() return render(request,'index.html',{'publish':obj_publish}) if request.method == "POST": booke_name = request.POST.get('bookname' ,None) price = request.POST.get('price' ,None) publish_id = request.POST.get('name' ,None) print(booke_name,price,publish_id) models.Book.objects.create(name=booke_name,price=price,publish_id=publish_id) return redirect('/person.html') def person(request): if request.method == "GET": obj_book = models.Book.objects.all() return render(request, 'person.html', {'obj_book': obj_book}) ~~~ >[info] ## html >[danger] ##### index.html ~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <form method="post"> {% csrf_token %} <table border="1px" cellspacing="0px"> <tr> <td>bookname</td> <td>price</td> <td>name</td> <td>操作</td> </tr> <tr> <td><input name="bookname"></td> <td><input name="price"></td> <td> <select name="name"> {% for i in publish %} <option value="{{ i.id }}">{{ i.name }}</option> {% endfor %} </select> </td> <td><input type="submit"></td> </tr> </table> </form> </body> </html> ~~~ * * * * * >[danger] ##### person.html ~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <form method="post"> <table border="1px" cellspacing="0px"> <tr> <td>bookname</td> <td>price</td> <td>pud_data</td> <td>name</td> <td>city</td> <td>操作</td> </tr> <tr> {% for i in obj_book %} <td>{{ i.name }}</td> <td>{{ i.price }}</td> <td>{{ i.pub_data }}</td> <td>{{ i.publish.name }}</td> <td>{{ i.publish.city}}</td> {% endfor %} </tr> </table> </form> </body> </html> ~~~
                  <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>

                              哎呀哎呀视频在线观看