app.py - from flask import Flask render_template request redirect url_for session from flask_mysqldb import MySQL MySQLdb import bcrypt import re app =

app.py - from flask import Flask render_template request...

This preview shows page 1 - 2 out of 2 pages.

from flask import Flask, render_template, request, redirect, url_for, sessionfrom flask_mysqldb import MySQL, MySQLdbimport bcryptimport reapp = Flask(__name__)app.config['MYSQL_HOST'] = 'localhost'app.config['MYSQL_USER'] = 'root'app.config['MYSQL_PASSWORD'] = ''app.config['MYSQL_DB'] = 'matcha'app.config['MYSQL_CURSORCLASS'] = 'DictCursor'mysql = MySQL(app)@app.route('/matcha/', methods=['GET', 'POST'])def login():# Output message if something goes wrong...msg = ''# Check if "username" and "password" POST requests exist (user submitted form)if request.method == 'POST' and 'username' in request.form and 'password' inrequest.form:# Create variables for easy accessusername = request.form['username']password = request.form['password']# Check if account exists using MySQLcursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)cursor.execute('SELECT * FROM accounts WHERE username = %s AND password = %s', (username, password,))# Fetch one record and return resultaccount = cursor.fetchone()# If account exists in accounts table in out databaseif account:
Background image
Image of page 2

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture