-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.py
More file actions
46 lines (38 loc) · 1.72 KB
/
basic.py
File metadata and controls
46 lines (38 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from flask import Flask, render_template, url_for, flash, redirect
from forms import RegistrationForm
from flask_behind_proxy import FlaskBehindProxy
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
proxied = FlaskBehindProxy(app)
app.config['SECRET_KEY'] = 'd9c5551c8207a27f1b62a329b095214d'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
db = SQLAlchemy(app)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(20), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
password = db.Column(db.String(60), nullable=False)
def __repr__(self):
return f"User('{self.username}', '{self.email}')"
@app.route("/")
def hello_world2():
return render_template('home.html', subtitle='Home Page', text='This is the home page')
@app.route("/home")
def hello_world():
return render_template('home.html', subtitle='Home Page', text='This is the home page')
@app.route("/second_page")
def second_page():
return render_template('second_page.html', subtitle='Second Page', text='This is the second page')
@app.route("/register", methods=['GET', 'POST'])
def register():
form = RegistrationForm()
if form.validate_on_submit(): # checks if entries are valid
user = User(username=form.username.data, email=form.email.data, password=form.password.data)
print(user)
db.session.add(user)
db.session.commit()
flash(f'Account created for {form.username.data}!', 'success')
return redirect(url_for('hello_world')) # if so - send to home page
return render_template('register.html', title='Register', form=form)
if __name__ == '__main__':
app.run(debug=True, host="0.0.0.0")