from flask import Flask, render_template, request, session, redirect, g, url_for import model app = Flask(__name__) app.secret_key = 'my-SECRET_key' username = '' user = model.check_users() @app.route('/', methods=['GET']) def home(): return render_template('signin.html') @app.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': session.pop('username', None) areyouuser = request.form['username'] pwd = model.check_pwd(areyouuser) if request.form['password'] == pwd: session['username'] = request.form['username'] return redirect(url_for('about')) return render_template('signin.html') '''if request.method == 'GET': return render_template('index.html') else: username = request.form['username']
from flask import Flask, render_template, redirect, url_for, request, redirect, g, session #call the model script you made before. import model app = Flask(__name__) #we need a secret KEY app.secret_key = 'jumpjacks' username = '' user = model.check_users() #this is going to be a function in model.py #what happens before before_request @app.before_request def before_request(): g.username = None if 'username' in session: g.username = session[ 'username'] #this calls an empty session as per username which is empty #in the route below: "/" means the home pages @app.route('/', methods=['GET']) #this is like how you see : www.google.com def home(): if 'username' in session: g.user = session['username'] #g is the global variable for flask return render_template('football.html', message='<img src = static/avatar.jpeg>')
from flask import Flask, render_template, request, session, redirect, url_for, g import model app = Flask(__name__,static_url_path="", static_folder="static") app.secretkey = 'jumpjacks' username = '******' user = model.check_users('username') @app.route('/', methods = ['GET']) def home(): return render_template ('index.html') @app.route('/about', methods = ['GET']) def about(): return render_template ('about.html') @app.route('/terms-of-use', methods = ['GET']) def terms(): return render_template ('terms.html') @app.route('/privacy', methods = ['GET']) def privacy(): return render_template ('privacy.html') @app.route('/portal', methods = ['GET', 'POST']) def portal(): if 'username' in session: g.user=session['username']
from flask import Flask, render_template, redirect, url_for, request, redirect, g, session #these are the models from before. import model app = Flask(__name__) #we need a secret KEY app.secret_key = 'atwine-gwerU78h' username = '' user = model.check_users() #this checks the user #what happens before before_request @app.before_request def before_request(): g.username = None if 'username' in session: g.username = session[ 'username'] #this calls an empty session as per username which is empty # 1|Gordon|Ramsy # 2|Ironman|Tonny # 3|Atwine|12345 #this is the login page @app.route('/', methods=['GET', 'POST']) #this is like how you see : www.google.com