时间:2024-01-21 15:30:01 | 来源:网站运营
时间:2024-01-21 15:30:01 来源:网站运营
如何用Python写一个小网站?:from flask import *app = Flask(__name__)@app.route('/')def hello_world(): return 'Hello World!'if __name__=="__main__": app.run(host='0.0.0.0',port=8080) # 0.0.0.0地址可给本机所有的IP地址访问
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Wow</title></head><body> <h1>我超级帅喔!</h1></body></html>
from flask import Flask,render_template,requestapp = Flask(__name__)@app.route('/')def hello_world(): return 'Hello World!' @app.route('/index')def index(): return render_template('index.html') #会自动找templates文件夹里面的index.html,并不需要一个绝对路径。if __name__=="__main__": app.run(host='0.0.0.0',port=8080) # 0.0.0.0地址可给本机所有的IP地址访问
from flask import Flask,render_template,requestapp = Flask(__name__)@app.route('/')def hello_world(): return 'Hello World!' @app.route('/index')def index(): return render_template('index.html') #会自动找templates文件夹里面的index.html,并不需要一个绝对路径。@app.route('/login')def index(): return render_template('login.html') @app.route('/content')def index(): return render_template('content.html') if __name__=="__main__": app.run(host='0.0.0.0',port=8080)
// login.html<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title></head><body> <form action="/login_finsh" method="POST"> 用户名 <input type="text" name="username" id=""> 密码 <input type="text" name="password" id=""> <input type="submit" value="登录"> </br> <input type="button" value="open1"> </br> <button type="button" onclick="open_function()"> open1</button> </form></body></html>
// content.html<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title></head><body> <p>这是内容页!</p></body></html>
关键词: