Last active
September 18, 2021 13:10
-
-
Save lorenzobn/ee61f003f9c6b59a2df42663b4c94d3d to your computer and use it in GitHub Desktop.
Basic Flask web application with login form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, render_template, redirect, request, url_for, flash | |
import os | |
app = Flask(__name__) | |
@app.route("/") | |
def index(): | |
return render_template('index.html') | |
@app.route("/login", methods=['GET', 'POST']) | |
def login(): | |
form_user = request.form.get("username") | |
form_pass = request.form.get("password") | |
if request.method == 'POST': | |
if form_user == app.config["USER"] and form_pass == app.config["PASS"]: | |
return render_template('success.html') | |
else: | |
flash("Invalid credentials. Please try again.") | |
return redirect(url_for("index")) | |
if __name__ == "__main__": | |
app.config["USER"] = "username" | |
app.config["PASS"] = "password" | |
app.config["SECRET_KEY"] = os.urandom(16).hex() | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment