当前位置:网站首页>使用flask和h5搭建网站/应用的简要步骤
使用flask和h5搭建网站/应用的简要步骤
2022-04-23 08:25:00 【7frog7】
在 传送门 的基础上,做一些修改、加了一些功能。
之前很早就想试试自己全栈做一个网站 算是补齐了一些知识。
简单地描述一下开发页面的过程。
使用了mdui
1.先规划好页面
最开始想找个accept相关的图标 但是发现accessible用上去更有趣
题目列表可以通过在特定模块添加代码的方式实现 很有趣
像这样
document.getElementById('plists').innerHTML += "<a href='/group?id="+String(i+(pro_id-1)*15)+"' class='mdui-list-item mdui-ripple mdui-col-offset-md-2'><i class='mdui-icon mdui-list-item-icon material-icons'>accessible</i><div class='mdui-list-item-content'>"+String(i+(pro_id-1)*15)+' '+ptitle+"</div></li>";
2.编写路由
以上图为例 需要编写至少2个路由
a.网页本身的路由
@app.route("/contestlist")
def contestlist():
return send_from_directory(root,'grouplist.htm')
b.页面获取信息方法的路由
@app.route("/contests",methods=['POST'])
def contests():
data=json.loads(request.get_data(as_text=True))
page=int(data['page'])
return contest_file('html/problem/groups',page)
def contest_file(file_dir,page):
problems={
"id":"href"}
start_id=(page-1)*15+1000
end_id=page*15+1000-1
for i in range(start_id,end_id):
try:
f=read_file_as_str('html/problem/groups/'+str(i)+'.json')
f = f.replace('\'','\"')
data=json.loads(f)
problems[str(i)]=data['name']
except:
problems[str(i)]='NotFound'
return json.dumps(problems)
3.连接前后端方法的功能函数
比如post一个请求 再收到信息写入到网页上
<script> if (pro_id === undefined){
pro_id = [1]; } var httpRequest = new XMLHttpRequest();//第一步:创建需要的对象 httpRequest.open('POST', '/contests', true); //第二步:打开连接 httpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");//设置请求头 注:post方式必须设置请求头(在建立连接后设置请求头) var data={
'page':pro_id[0]}; httpRequest.send(JSON.stringify(data)); httpRequest.onreadystatechange = function () {
//请求后的回调接口,可将请求成功后要执行的程序写在其中 if (httpRequest.readyState == 4 && httpRequest.status == 200) {
//验证请求是否发送成功 var json = httpRequest.responseText;//获取到服务端返回的数据 var info = JSON.parse(json); var page=pro_id; var start_id=(page-1)*15+1000; var end_id=page*15+1000-1; console.log(info); for(var i=start_id;i<end_id;i++){
var ptitle=info[(i)]; if(ptitle=='NotFound'){
continue; } document.getElementById('plists').innerHTML += "<a href='/group?id="+String(i+(pro_id-1)*15)+"' class='mdui-list-item mdui-ripple mdui-col-offset-md-2'><i class='mdui-icon mdui-list-item-icon material-icons'>accessible</i><div class='mdui-list-item-content'>"+String(i+(pro_id-1)*15)+' '+ptitle+"</div></li>"; } } }; </script>
4.调整布局 debug
版权声明
本文为[7frog7]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_45817880/article/details/124241840
边栏推荐
- K210学习笔记(二) K210与STM32进行串口通信
- The annotation is self-defined by implementing the parameter parser handlermethodargumentresolver interface
- [explanation] get ora-12838: cannot read / modify an object after modifying it in parallel
- okcc呼叫中心外呼系统智能系统需要用多大的盘存录音?
- Test your machine learning pipeline
- 一个必看的微信小程序开发指南1-基础知识了解
- Redis Desktop Manager for Mac(Redis可视化工具)
- ELK生产实践
- QT compilation qtxlsx Library
- 耳穴诊疗随笔0421
猜你喜欢
如何保护开源项目免遭供应链攻击-安全设计(1)
Yangtao electronic STM32 Internet of things introduction 30 steps notes 1. The difference between Hal library and standard library
SYS_CONNECT_BY_PATH(column,'char') 结合 start with ... connect by prior
On time atom joins hands with oneos live broadcast, and the oneos system tutorial is fully launched
Qtablewidget header customization and beautification developed by pyqt5 (with source code download)
IDEA导入commons-logging-1.2.jar包
xctf刷题小记
Reference passing 1
一个必看的微信小程序开发指南1-基础知识了解
ELK生产实践
随机推荐
QFileDialog select multiple files or folders
Ajax cache prevention method
Using qlst excel file
[learning] audio and video development from scratch (9) -- nuplayer
Failed to convert a NumPy array to a Tensor(Unsupported Object type int)
STM32 uses Hal library. The overall structure and function principle are introduced
获取TrustedInstaller权限
QT compilation qtxlsx Library
pgsql想实现mysql一样样的列子查询操作
lgb,xgb,cat k折交叉验证
Notes on English class (4)
Redis master-slave server problem
【精品】利用动态代理实现事务统一管理 二
经典题目刷一刷
Notes on 30 steps of introduction to Internet of things of yangtao electronics STM32 III. Explanation of new cubeide project and setting
How to encrypt devices under the interconnection of all things
LeetCode-199-二叉树的右视图
对li类数组对象随机添加特性,并进行排序
DOM learning notes - traverse all element nodes of the page
RPC过程