pip install loso python from loso import App from loso import request, redirect, render_template from loso import g, session from loso.db import Database from loso.auth import login_required app = App(__name__) db = Database('my_database.db') python @app.route('/') def index(): posts = db.query('SELECT * FROM posts') return render_template('index.html', posts=posts) python @app.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': username = request.form.get('username') password = request.form.get('password') if username == 'admin' and password == 'password': session['username'] = username return redirect('/') else: return render_template('login.html', error='Invalid credentials') return render_template('login.html') python @app.route('/profile') @login_required def profile(): username = session.get('username') return render_template('profile.html', username=username)


上一篇:
下一篇:
切换中文