django前后端不分离入门
2022/9/5 23:22:54
本文主要是介绍django前后端不分离入门,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
在django中创建html模板,关联数据,返回给浏览器
修改settings.py文件
将 'DIRS': [] 修改为'DIRS': [os.path.join(BASE_DIR, 'templates')],
项目目录下创建模板文件夹templates
templates下创建模板文件index.html
<!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>
views.py编写
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"})
urls.py指定路由
...
浏览器访问测试
#html文件有修改,保存并刷新浏览器即可显示最新内容。
这篇关于django前后端不分离入门的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-04-01got an unexpected keyword argument
- 2024-03-30维多利亚的秘密 golang入坑系统
- 2024-03-29mongodb sort by date
- 2024-03-29go swagger
- 2024-03-25mongodb cdc
- 2024-03-25how to use go in vscode
- 2024-03-22mongooseserverselectionerror: connect econnrefused ::1:27017
- 2024-03-21pymongo insert_many
- 2024-03-18projection mongodb
- 2024-03-14clickhouse-go