Started from scratch and failed
Issue with register_blueprint
This commit is contained in:
@@ -1,84 +1,5 @@
|
||||
from datetime import datetime
|
||||
|
||||
from flask import Flask, flash, request, render_template
|
||||
from flask.helpers import url_for
|
||||
from flask.json import jsonify
|
||||
from flask_bootstrap import Bootstrap
|
||||
from pymongo import MongoClient
|
||||
from pymongo.errors import ConnectionFailure
|
||||
from flask_wtf.csrf import CSRFProtect, CSRFError
|
||||
from flask_mail import Mail
|
||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
|
||||
from common.security import check_keyfile_exists, generate_keyfile
|
||||
from config import ProductionConfig as Config
|
||||
|
||||
def create_app():
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(Config())
|
||||
|
||||
from common.blueprints import cookie_consent
|
||||
|
||||
from admin.views import views as admin_views
|
||||
from admin.auth import auth as admin_auth
|
||||
from admin.results import results
|
||||
from quiz.views import views as quiz_views
|
||||
|
||||
app.register_blueprint(quiz_views, url_prefix = '/')
|
||||
app.register_blueprint(admin_views, url_prefix = '/admin/')
|
||||
app.register_blueprint(admin_auth, url_prefix = '/admin/')
|
||||
app.register_blueprint(results, url_prefix = '/admin/results/')
|
||||
|
||||
app.register_blueprint(cookie_consent, url_prefix = '/cookies/')
|
||||
|
||||
@app.before_request
|
||||
def check_cookie_consent():
|
||||
if request.cookies.get('cookie_consent') == 'True':
|
||||
return
|
||||
if any([ request.path.startswith(x) for x in [ '/admin/static/', '/static/', '/cookies/' ] ]):
|
||||
return
|
||||
flash(f'<strong>Cookie Consent</strong>: This web site only stores minimal, functional cookies. By using this site, you consent to this use of cookies. For more information, see our <a href="{url_for("quiz_views.privacy")}">privacy policy</a>.', 'cookie_alert')
|
||||
|
||||
from admin.views import check_login, get_user_from_db, get_id_from_cookie
|
||||
|
||||
@app.context_processor
|
||||
def inject_now():
|
||||
return {'now': datetime.utcnow()}
|
||||
|
||||
@app.context_processor
|
||||
def _check_login():
|
||||
return dict(check_login = check_login)
|
||||
|
||||
@app.context_processor
|
||||
def _get_user_from_db():
|
||||
return dict(get_user_from_db = get_user_from_db)
|
||||
|
||||
@app.context_processor
|
||||
def _get_id_from_cookie():
|
||||
return dict(get_id_from_cookie = get_id_from_cookie)
|
||||
|
||||
@app.errorhandler(404)
|
||||
def _404_handler(e):
|
||||
return render_template('/quiz/404.html'), 404
|
||||
|
||||
@app.errorhandler(CSRFError)
|
||||
def csrf_error_handler(error):
|
||||
return jsonify({ 'error': 'Could not validate a secure connection.'} ), 400
|
||||
|
||||
if not check_keyfile_exists():
|
||||
generate_keyfile()
|
||||
|
||||
Bootstrap(app)
|
||||
csrf = CSRFProtect(app)
|
||||
|
||||
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1)
|
||||
|
||||
return app
|
||||
|
||||
#!/bin/env python
|
||||
from distutils.log import debug
|
||||
from app import create_app
|
||||
app = create_app()
|
||||
mongo = MongoClient(app.config['MONGO_URI'])
|
||||
db = mongo[app.config['MONGO_INITDB_DATABASE']]
|
||||
mail = Mail(app)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host=app.config['APP_HOST'])
|
||||
if __name__ == '__main__': app.run()
|
Reference in New Issue
Block a user