使用rander() 将后台的数据传递到前台界面显示出来

1、创建templates文件夹

2、在该文件夹内创建html界面a.html

3.views.py:

  def a(request):

    love='iloveyou'
    return render(request,'a.html',{'aaa':love})

4.a.html

  <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    </head>
    <body>
      <center>
        <h1>{{ aaa }}</h1>
      </center>
    </body>
    </html>

5、setting.py配置只需配置一次即可

  TEMPLATES = ['DIRS': [os.path.join(BASE_DIR, 'templates')],]

猜你喜欢

转载自www.cnblogs.com/ziyun20160613/p/10096404.html
今日推荐