generated from nighthawkcoders/flask_portfolio
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathmain.py
66 lines (49 loc) · 2.01 KB
/
main.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import threading
# import "packages" from flask
from flask import render_template,request # import render_template from "public" flask libraries
from flask.cli import AppGroup
# import "packages" from "this" project
from __init__ import app, db, cors # Definitions initialization
# setup APIs
from api.user import user_api # Blueprint import api definition
from api.player import player_api
# database migrations
from model.users import initUsers
from model.players import initPlayers
# setup App pages
from projects.projects import app_projects # Blueprint directory import projects definition
# Initialize the SQLAlchemy object to work with the Flask app instance
db.init_app(app)
# register URIs
app.register_blueprint(user_api) # register api routes
app.register_blueprint(player_api)
app.register_blueprint(app_projects) # register app pages
@app.errorhandler(404) # catch for URL not found
def page_not_found(e):
# note that we set the 404 status explicitly
return render_template('404.html'), 404
@app.route('/') # connects default URL to index() function
def index():
return render_template("index.html")
@app.route('/table/') # connects /stub/ URL to stub() function
def table():
return render_template("table.html")
@app.before_request
def before_request():
# Check if the request came from a specific origin
allowed_origin = request.headers.get('Origin')
if allowed_origin in ['http://localhost:4100', 'http://127.0.0.1:4100', 'https://nighthawkcoders.github.io']:
cors._origins = allowed_origin
# Create an AppGroup for custom commands
custom_cli = AppGroup('custom', help='Custom commands')
# Define a command to generate data
@custom_cli.command('generate_data')
def generate_data():
initUsers()
initPlayers()
# Register the custom command group with the Flask application
app.cli.add_command(custom_cli)
# this runs the application on the development server
if __name__ == "__main__":
# change name for testing
app.run(debug=True, host="0.0.0.0", port="8086")