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

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, session from flask_mysqldb import MySQL,MySQLdb import bcrypt app = Flask(__name__) app.config['MYSQL_HOST'] = 'localhost' app.config['MYSQL_USER'] = 'root' app.config['MYSQL_PASSWORD'] = '' app.config['MYSQL_DB'] = 'flaskdb' app.config['MYSQL_CURSORCLASS'] = 'DictCursor' mysql = MySQL(app) @app.route('/') def home(): return render_template("home.html") @app.route('/register', methods=['GET', 'POST']) def register(): if request.method == 'GET': return render_template("register.html") else: name = request.form['name'] kodedosen = request.form['kodedosen'] password = request.form['password'].encode('utf-8') cur = mysql.connection.cursor() cur.execute("INSERT INTO users (name, kodedosen, password) VALUES (%s, %s,%s)",(name,kodedosen,password,)) mysql.connection.commit() return redirect(url_for('home')) @app.route('/login',methods=['GET','POST']) def login(): if request.method == 'POST': kodedosen = request.form['kodedosen'] password = request.form['password'].encode('utf-8') hash_password = bcrypt.hashpw(password, bcrypt.gensalt()) curl = mysql.connection.cursor(MySQLdb.cursors.DictCursor) curl.execute("SELECT * FROM users WHERE kodedosen=%s",(kodedosen,))
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read both pages?

  • Fall '19
  • flask import Flask, kodedosen, mysqldb import MySQL

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture