時間:2024-01-21 15:30:01 | 來源:網(wǎng)站運營
時間:2024-01-21 15:30:01 來源:網(wǎng)站運營
如何用Python寫一個小網(wǎng)站?: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>這是內(nèi)容頁!</p></body></html>
關(guān)鍵詞:
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。