![]() |
4 years ago | |
---|---|---|
__pycache__ | 4 years ago | |
templates | 4 years ago | |
theme | 4 years ago | |
README.md | 4 years ago | |
app.py | 4 years ago | |
data.db | 4 years ago | |
helper.py | 4 years ago | |
login.py | 4 years ago | |
output.html | 4 years ago | |
test.html | 4 years ago | |
todo.md | 4 years ago |
This is a simple forum built-in Flask framework in Python. The main code is less than 100 lines to be as lightweight as possible. For the moment the forum is very basic.
In the future I want to integrate the following ones as well
I made this forum because I want to make a serie of basic lightweight web apps that can be used to make other projects as well. I challenged myself to make apps with the following lines limits:
So these are the advantages:
In bonus you can also uses the 'login.py' script to speed up the devloppement of the account management in your own Flask apps.
Note: to change the style of the website I highly recommend you to use the 'Style inspector' built-in in Firefox.
Into your main app file you can add the following snippet:
# Import the login library
from login import *
# Create a class User and a variable db containing the database from sqlalchemy
# In the login page back end:
@app.route('/login')
def login():
try:
loginUser(request.form['username'], request.form['password'], User)
return 'You are now logged in. as ' + current_user.username
except:
return 'Username or password invalid.'
@app.route('/register')
def register():
try:
createUser(request.form['username'], request.form['password'], db, User)
return 'New account created, you are logged in.'
except:
return 'An error occurs, probably because this username is already taken.'
@app.route('/logout')
def logout():
logout_user()
return 'You are logged out.'
This is the class User:
class User(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.Text, unique=True)
password = db.Column(db.Text)
def __init__(self, username, password):
self.username = username
self.password = password