Improved structure
- Flask app factory instead of initializing `app` variable - Gunicorn for production server - Makefile: python3 -m - .gitignore: instance dir
This commit is contained in:
parent
058bcd13e5
commit
9ead8a457c
6 changed files with 30 additions and 18 deletions
|
@ -1,3 +0,0 @@
|
|||
"""Init file for the module"""
|
||||
|
||||
from .app import app
|
|
@ -1,20 +1,33 @@
|
|||
"""Flask web application
|
||||
main script"""
|
||||
"""Flask web application main script"""
|
||||
|
||||
import os
|
||||
import secrets
|
||||
from pathlib import Path
|
||||
|
||||
from flask import Flask
|
||||
|
||||
|
||||
root = Path('..')
|
||||
static = str(root / 'static')
|
||||
tmpl = str(root / 'templates')
|
||||
def create_app() -> Flask:
|
||||
"""Flask app factory function"""
|
||||
|
||||
app = Flask(
|
||||
'${REPO_NAME_SNAKE}',
|
||||
static_folder=static,
|
||||
template_folder=tmpl,
|
||||
)
|
||||
root = Path('..')
|
||||
static = str(root / 'static')
|
||||
tmpl = str(root / 'templates')
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
app = Flask(
|
||||
__name__,
|
||||
static_folder=static,
|
||||
template_folder=tmpl,
|
||||
instance_relative_config=True,
|
||||
)
|
||||
app.config['SECRET_KEY'] = os.getenv(
|
||||
'SECRET_KEY',
|
||||
secrets.token_hex(32),
|
||||
)
|
||||
|
||||
try:
|
||||
os.makedirs(app.instance_path)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
return app
|
||||
|
|
Loading…
Add table
Reference in a new issue