#源码说明
学习flask框架的可以看看,运行以下代码,记得pip list看看你电脑环境有没有预装以下源码import 导入的插件,没有请使用pip install 插件名下载安装
新建一个文件夹,例如python 进入该文件夹,创建demo.py并复制以下python代码放置进去,其次下载文章末尾的附件templates压缩包解压后放置到python文件夹下,后面就可以使用运行python的方式运行demo.py了,若有不懂可以添加久伴博客官方交流群,在文章末尾哦
#python 源码
# 导入flask对象 from flask import Flask, render_template, request, redirect, url_for, session import functools # 当前文件名 app = Flask(__name__) app.secret_key = '3a3a3a3a3a3a3aa3' DATA_LIST = { 1: {'name': '测试姓名', 'age': '26'}, } def auth(func): @functools.wraps(func) def inner(*args, **kwargs): username = session.get('xxx') if not username: return redirect(url_for('login')) return func(*args, **kwargs) return inner # 登录路由 @app.route('/login', methods=['GET', 'POST']) def login(): if request.method == "GET": return render_template('login.html') user = request.form.get('user') pwd = request.form.get('pwd') if user == 'jiub' and pwd == '123456': session['xxx'] = 'jiub' return redirect('/index') error = '用户名或密码错误' return render_template('login.html', error=error) # 首页路由 @app.route('/index', endpoint='idx') @auth def index(): data_list = DATA_LIST return render_template('qqq.html', data_list=data_list) # 修改路由 @app.route('/edit/', methods=['GET', 'POST']) @auth def edit(nid): if request.method == "GET": info = DATA_LIST[nid] return render_template('edit.html', info=info) jid = nid user = request.form.get('user') age = request.form.get('age') print(age) DATA_LIST[jid]['name'] = user DATA_LIST[jid]['age'] = age return redirect(url_for('idx')) # 删除路由 @app.route('/del/ ') @auth def delete(nid): del DATA_LIST[nid] print(nid) return redirect(url_for('idx')) # 增加路由 @app.route('/add', methods=['GET', "POST"]) @auth def add(): if request.method == "GET": return render_template('add.html') # id = request.form.get('id') user = request.form.get('user') age = request.form.get('age') k = 0 for k in DATA_LIST: id = k+1 for i in DATA_LIST: if i == id: # 判断接受的id编号是否重复,如果id重复跳转,新增页面 # print('id重复') error = 'ID重复' return render_template('add.html', error=error) DATA_LIST[id] = {'name': user, 'age': age} return redirect('/index') if __name__ == '__main__': app.run(debug=True, host='192.168.40.8', port=80)
加群入久伴博客官方微信群
加入久伴官方微信群有啥优势?
1.文章内部资源由于时间久远可能失效,加群,群内可以第一时间反馈
2.网站中教程不一定适用任何人,加群可以第一时间咨询并解决您得疑惑
3.你游荡于互联网,也需要群体,加群一起互动交流,畅所欲言
扫描下方二维码即可加入交流讨论

I mighttttt be getting fucked in the ass tonight, we’ll see how it goes? https://is.gd/dBsd60
Wishing for a new cock to have some fun with https://is.gd/dBsd60
Have me from behind! https://snip.ly/6327oi
Can I squat on you next? http://tiny.cc/gz35vz
Anybody looking for a smoke buddy? http://prephe.ro/y6sn
I want someone other than my husband to cover my ass in cum http://prephe.ro/Bdsn