在django中创建html模板,关联数据,返回给浏览器
将 'DIRS': [] 修改为'DIRS': [os.path.join(BASE_DIR, 'templates')],
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body class="globcss"> <table border="0" class="tablecss"> <tr> <td class="keycss">{{key0}}</td> <td class="valuecss"> {{value0}}</td> </tr> </table> <div class="line"></div> <table border="0" class="tablecss"> <tr> <td class="keycss">{{key10}}</td> <td class="valuecss"> {{value10}}</td> </tr> </table> <div class="line"></div> </body> </html> <style> .globcss { font-size: 36px; line-height: 2em; width: 100%; height: 100%; background-color: #f3f4f6; } .tablecss { width: 100%; } .keycss { color: green; width: 18%; text-align-last: justify; } .valuecss { color: #000000; } .trcss { margin-top: 100px; } .div1{ } .line{ width: 100%; border-bottom: 1px solid #000000; color:green; } .test{ background-color: #a3f4f6; } </style>
from django.shortcuts import render from django.http import HttpResponse from django.core import serializers def get_data(request): ... return render(request, "index.html",{"key0": "11", "value0": "22"}) #return render(request, "err.html", {"err": "404"})
...
#html文件有修改,保存并刷新浏览器即可显示最新内容。