You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
suchwow/suchwow/app.py

46 lines
1.2 KiB
Python

import json
from flask import Flask, request, session
from flask import render_template, flash
from flask_session import Session
from suchwow.models import Post, Profile, Comment, Notification, db
from suchwow.routes import auth, comment, post, profile
from suchwow.utils.decorators import login_required
app = Flask(__name__)
app.config.from_envvar("FLASK_SECRETS")
app.secret_key = app.config["SECRET_KEY"]
Session(app)
app.register_blueprint(post.bp)
app.register_blueprint(auth.bp)
@app.route("/")
def index():
itp = 20
page = request.args.get("page", 1)
try:
page = int(page)
except:
flash("Wow, wtf hackerman. Cool it.")
page = 1
posts = Post.select().order_by(Post.timestamp.desc()).paginate(page, itp)
total_pages = round(Post.select().count() / itp)
return render_template("index.html", posts=posts, page=page, total_pages=total_pages)
@app.route("/about")
def about():
return render_template("about.html")
@app.errorhandler(404)
def not_found(error):
return "nothin there, brah"
@app.cli.command("dbinit")
def dbinit():
db.create_tables([Post, Profile, Comment, Notification])
if __name__ == "__main__":
app.run()