Started from scratch and failed
Issue with register_blueprint
This commit is contained in:
52
ref-test/app/__init__.py
Normal file
52
ref-test/app/__init__.py
Normal file
@ -0,0 +1,52 @@
|
||||
from .bootstrap import bootstrap
|
||||
from .config import DevelopmentConfig as Config
|
||||
from .csrf import csrf
|
||||
from .database import db
|
||||
from .login_manager import login_manager
|
||||
from .mail import mail
|
||||
|
||||
from flask import Flask
|
||||
from flask_wtf.csrf import CSRFError
|
||||
from flask.json import jsonify
|
||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from .admin.views import admin
|
||||
from .api.views import api
|
||||
from .common.views import common
|
||||
from .quiz.views import quiz
|
||||
|
||||
def create_app():
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(Config())
|
||||
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto= 1, x_host= 1)
|
||||
|
||||
# bootstrap.init_app(app)
|
||||
# csrf.init_app(app)
|
||||
# db.init_app(app)
|
||||
# login_manager.init_app(app)
|
||||
# mail.init_app(app)
|
||||
|
||||
# login_manager.login_view = 'admin._login'
|
||||
# @login_manager.user_loader
|
||||
# def _load_user(user_id):
|
||||
# pass
|
||||
|
||||
# @app.errorhandler(404)
|
||||
# def _404_handler(error):
|
||||
# return jsonify({'error':'404 — Not Found'}), 404
|
||||
# @app.errorhandler(CSRFError)
|
||||
# def _csrf_handler():
|
||||
# return jsonify({'error':'Could not validate a secure connection.'}), 403
|
||||
# @app.context_processor
|
||||
# def _now():
|
||||
# return {'now': datetime.utcnow()}
|
||||
|
||||
app.register_blueprint(admin, url_prefix='/admin')
|
||||
app.register_blueprint(api, url_prefix='/api')
|
||||
app.register_blueprint(common)
|
||||
app.register_blueprint(quiz)
|
||||
|
||||
return app
|
0
ref-test/app/admin/__init__.py
Normal file
0
ref-test/app/admin/__init__.py
Normal file
20
ref-test/app/admin/views/__init__.py
Normal file
20
ref-test/app/admin/views/__init__.py
Normal file
@ -0,0 +1,20 @@
|
||||
from flask import Blueprint
|
||||
|
||||
admin = Blueprint(
|
||||
name='admin',
|
||||
import_name=__name__,
|
||||
template_folder='templates',
|
||||
static_folder='static'
|
||||
)
|
||||
|
||||
@admin.route('/')
|
||||
@admin.route('/home/')
|
||||
@admin.route('/dashboard/')
|
||||
def _home():
|
||||
return 'Home Page'
|
||||
|
||||
@admin.route('/settings/')
|
||||
def _settings():
|
||||
return 'Settings Page'
|
||||
|
||||
from . import auth, questions, results, tests, users
|
21
ref-test/app/admin/views/auth.py
Normal file
21
ref-test/app/admin/views/auth.py
Normal file
@ -0,0 +1,21 @@
|
||||
from . import admin
|
||||
|
||||
@admin.route('/login/')
|
||||
def _login():
|
||||
return 'Login Page'
|
||||
|
||||
@admin.route('/logout/')
|
||||
def _logout():
|
||||
return 'Logout Command'
|
||||
|
||||
@admin.route('/register/')
|
||||
def _register():
|
||||
return 'Registration Page'
|
||||
|
||||
@admin.route('/reset/')
|
||||
def _reset():
|
||||
return 'Reset Page'
|
||||
|
||||
@admin.route('/update_password/', methods=['POST'])
|
||||
def _update_password():
|
||||
return 'Password Update'
|
0
ref-test/app/admin/views/questions.py
Normal file
0
ref-test/app/admin/views/questions.py
Normal file
0
ref-test/app/admin/views/results.py
Normal file
0
ref-test/app/admin/views/results.py
Normal file
0
ref-test/app/admin/views/tests.py
Normal file
0
ref-test/app/admin/views/tests.py
Normal file
6
ref-test/app/admin/views/users.py
Normal file
6
ref-test/app/admin/views/users.py
Normal file
@ -0,0 +1,6 @@
|
||||
from . import admin
|
||||
|
||||
@admin.route('/settings/users/')
|
||||
def _users():
|
||||
return 'Manage Users'
|
||||
|
14
ref-test/app/api/views/__init__.py
Normal file
14
ref-test/app/api/views/__init__.py
Normal file
@ -0,0 +1,14 @@
|
||||
from flask import Blueprint
|
||||
|
||||
api = Blueprint(
|
||||
name='api',
|
||||
import_name=__name__
|
||||
)
|
||||
|
||||
@api.route('/questions/', methods=['POST'])
|
||||
def _fetch_questions():
|
||||
return 'Fetch Questions'
|
||||
|
||||
@api.route('/submit/', methods=['POST'])
|
||||
def _submit_quiz():
|
||||
return 'Submit Quiz'
|
3
ref-test/app/bootstrap.py
Normal file
3
ref-test/app/bootstrap.py
Normal file
@ -0,0 +1,3 @@
|
||||
from ensurepip import bootstrap
|
||||
from flask_bootstrap import Bootstrap
|
||||
bootstrap = Bootstrap()
|
10
ref-test/app/common/views/__init__.py
Normal file
10
ref-test/app/common/views/__init__.py
Normal file
@ -0,0 +1,10 @@
|
||||
from flask import Blueprint
|
||||
|
||||
common = Blueprint(
|
||||
name='common',
|
||||
import_name=__name__,
|
||||
template_folder='templates',
|
||||
static_folder='static'
|
||||
)
|
||||
|
||||
from . import privacy
|
5
ref-test/app/common/views/privacy.py
Normal file
5
ref-test/app/common/views/privacy.py
Normal file
@ -0,0 +1,5 @@
|
||||
from . import common
|
||||
|
||||
@common.route('/privacy/')
|
||||
def _privacy():
|
||||
return 'Privacy Policy'
|
44
ref-test/app/config.py
Normal file
44
ref-test/app/config.py
Normal file
@ -0,0 +1,44 @@
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
|
||||
class Config(object):
|
||||
APP_HOST = '0.0.0.0'
|
||||
DEBUG = False
|
||||
TESTING = False
|
||||
SECRET_KEY = os.getenv('SECRET_KEY')
|
||||
SERVER_NAME = os.getenv('SERVER_NAME')
|
||||
SESSION_COOKIE_SECURE = True
|
||||
SQLALCHEMY_DATABASE_URI = 'sqlite:///data/database.db'
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
|
||||
MAIL_SERVER = os.getenv("MAIL_SERVER")
|
||||
MAIL_PORT = int(os.getenv("MAIL_PORT"))
|
||||
MAIL_USE_TLS = False
|
||||
MAIL_USE_SSL = False
|
||||
MAIL_DEBUG = False
|
||||
MAIL_USERNAME = os.getenv("MAIL_USERNAME")
|
||||
MAIL_PASSWORD = os.getenv("MAIL_PASSWORD")
|
||||
MAIL_DEFAULT_SENDER = os.getenv("MAIL_DEFAULT_SENDER")
|
||||
MAIL_MAX_EMAILS = int(os.getenv("MAIL_MAX_EMAILS"))
|
||||
MAIL_SUPPRESS_SEND = False
|
||||
MAIL_ASCII_ATTACHMENTS = bool(os.getenv("MAIL_ASCII_ATTACHMENTS"))
|
||||
DATA_FILE_DIRECTORY = os.getenv("DATA_FILE_DIRECTORY")
|
||||
|
||||
class ProductionConfig(Config):
|
||||
pass
|
||||
|
||||
class DevelopmentConfig(Config):
|
||||
APP_HOST = '127.0.0.1'
|
||||
DEBUG = True
|
||||
SESSION_COOKIE_SECURE = False
|
||||
MAIL_SERVER = 'localhost'
|
||||
MAIL_DEBUG = True
|
||||
MAIL_SUPPRESS_SEND = False
|
||||
|
||||
class TestingConfig(DevelopmentConfig):
|
||||
TESTING = True
|
||||
SESSION_COOKIE_SECURE = False
|
||||
MAIL_SERVER = os.getenv("MAIL_SERVER")
|
||||
MAIL_DEBUG = True
|
||||
MAIL_SUPPRESS_SEND = False
|
2
ref-test/app/csrf.py
Normal file
2
ref-test/app/csrf.py
Normal file
@ -0,0 +1,2 @@
|
||||
from flask_wtf.csrf import CSRFProtect
|
||||
csrf = CSRFProtect()
|
2
ref-test/app/database.py
Normal file
2
ref-test/app/database.py
Normal file
@ -0,0 +1,2 @@
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
db = SQLAlchemy()
|
0
ref-test/app/forms/__init__.py
Normal file
0
ref-test/app/forms/__init__.py
Normal file
2
ref-test/app/install.py
Normal file
2
ref-test/app/install.py
Normal file
@ -0,0 +1,2 @@
|
||||
# if not database_exists(Config.SQLALCHEMY_DATABASE_URI): create_database(Config.SQLALCHEMY_DATABASE_URI)
|
||||
# with app.app_context(): db.create_all()
|
2
ref-test/app/login_manager.py
Normal file
2
ref-test/app/login_manager.py
Normal file
@ -0,0 +1,2 @@
|
||||
from flask_login import LoginManager
|
||||
login_manager = LoginManager()
|
2
ref-test/app/mail.py
Normal file
2
ref-test/app/mail.py
Normal file
@ -0,0 +1,2 @@
|
||||
from flask_mail import Mail
|
||||
mail = Mail()
|
0
ref-test/app/models/__init__.py
Normal file
0
ref-test/app/models/__init__.py
Normal file
0
ref-test/app/quiz/__init__.py
Normal file
0
ref-test/app/quiz/__init__.py
Normal file
29
ref-test/app/quiz/views/__init__.py
Normal file
29
ref-test/app/quiz/views/__init__.py
Normal file
@ -0,0 +1,29 @@
|
||||
from flask import Blueprint
|
||||
|
||||
quiz = Blueprint(
|
||||
name='quiz',
|
||||
import_name=__name__,
|
||||
template_folder='templates',
|
||||
static_folder='static'
|
||||
)
|
||||
|
||||
@quiz.route('/')
|
||||
@quiz.route('/home/')
|
||||
def _home():
|
||||
return 'Quiz Home Page'
|
||||
|
||||
@quiz.route('/instructions/')
|
||||
def _instructions():
|
||||
return 'Instructions'
|
||||
|
||||
@quiz.route('/start/')
|
||||
def _start():
|
||||
return 'Start Quiz'
|
||||
|
||||
@quiz.route('/quiz/')
|
||||
def _quiz():
|
||||
return 'Quiz Console'
|
||||
|
||||
@quiz.route('/result/')
|
||||
def _result():
|
||||
return 'Quiz Result'
|
10
ref-test/app/test.py
Normal file
10
ref-test/app/test.py
Normal file
@ -0,0 +1,10 @@
|
||||
from flask import Blueprint
|
||||
|
||||
foo = Blueprint(
|
||||
name='foo',
|
||||
import_name=__name__
|
||||
)
|
||||
|
||||
@foo.route('/')
|
||||
def testing():
|
||||
return 'Testing'
|
0
ref-test/app/tools/__init__.py
Normal file
0
ref-test/app/tools/__init__.py
Normal file
Reference in New Issue
Block a user