利用jupyter的cell是可以运行python文件的:
运行py文件例子:
In [ ]:%run lhr.py
加载了lhr.py文件,相当于导包。
In [ ]:%load lhr.py
把lhr.py的代码显示出来。
# %load app.py
from flask import Flask
from flask import render_template
from flask import request
from datetime import datetime
import re
import pymysql
app = Flask(__name__)
# @app.route("/")
# def home():
# return 'Hello, Flask!'
# @app.route("/hello/<name>")
# def hello_there(name):
# return render_template(
# "hello_there.html",
# name = name,
# date = datetime.now()
# )
# @app.route("/test2")
# def test2():
# return render_template(
# "test2.html"
# )
# @app.route("/api/data")
# def get_data():
# return app.send_static_file("data.json")
# Replace the existing home function with the one below
@app.route("/")
def home():
return render_template("home.html")
# New functions
@app.route("/about")
def about():
return render_template("about.html")
@app.route("/contact")
def contact():
return render_template("contact.html")
@app.route("/test2")
def test2():
return render_template(
"test2.html"
)
@app.route("/test3")
def test3():
return render_template(
"test3.html"
)
@app.route("/test4")
def test4():
return render_template(
"test4.html"
)
@app.route("/register")
def register():
return render_template(
"register.html"
)
@app.route("/result",methods = ['POST','GET'])
def result():
if request.method=='POST':
result = request.form
# print(result.get("name"))
# print(type(result.get("name")))
# print(result.get("gender"))
# print(type(result.get("gender")))
# print(result.get("age"))
# print(type(result.get("age")))
# print(result.get("level"))
# print(type(result.get("level")))
mname = result.get("name")
gender = "男" if result.get("gender")==None else "女"
age = result.get("age")
level = result.get("level")
print(mname,gender,age,level)
print(f"insert into members values(null,{mname},{gender},{age},{level})")
try:
print(1)
cursor.execute("use yacht_club")
print(2)
cursor.execute(f"insert into members values(null,'{mname}','{gender}',{age},{level})")
print(3)
conn.commit()
print(4)
except:
print(5)
return render_template(
"home.html"
)
else:
print(6)
return render_template(
"register.html"
# "result.html",result = result
)
if __name__ == '__main__':
conn = pymysql.connect(host='localhost',port=3306,user='root',passwd='20010529',charset = 'utf8')
cursor = conn.cursor()
app.run(host="192.168.126.1",port=5000,debug=True)
cursor.close()
conn.close()
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/102975.html