Exemplo n.º 1
0
def create_app():
    app = Flask(__name__)

    app.config['SECRET_KEY'] = 'Titokos_kulcs_12345'
    #app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'
    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://tempwriter:[email protected]/home'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    db.init_app(app)
    Migrate(app, db)
    Bootstrap(app)

    app.register_error_handler(404, page_not_found)
    app.register_error_handler(500, internal_server_error)

    login_manager = LoginManager()
    login_manager.login_view = 'auth.login'
    login_manager.init_app(app)

    from .models import User

    @login_manager.user_loader
    def load_user(user_id):
        # since the user_id is just the primary key of our user table, use it in the query for the user
        return User.query.get(int(user_id))

    # blueprint for auth routes in our app
    from .auth import auth as auth_blueprint
    app.register_blueprint(auth_blueprint)

    # blueprint for non-auth parts of app
    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    # blueprint registration api
    from app.api import bp as api_bp
    app.register_blueprint(api_bp, url_prefix='/api')

    # blueprint registration api
    from app.admin import bp as admin_bp
    app.register_blueprint(admin_bp, url_prefix='/admin')

    return app
Exemplo n.º 2
0
from flask_bs4 import Bootstrap
from flask_babel import Babel, lazy_gettext as _l
from flask_qrcode import QRcode
from flask_moment import Moment
from config import Config
import logging
from logging.handlers import RotatingFileHandler, SMTPHandler
import os

db = SQLAlchemy()
migrate = Migrate()
login = LoginManager()
login.login_view = 'auth.login'
login.login_message = _l('Please log in to access this page.')
mail = Mail()
bootstrap = Bootstrap()
babel = Babel()
qrcode = QRcode()
moment = Moment()


def create_app(config_class=Config):
    app = Flask(__name__)
    app.config.from_object(config_class)

    @app.context_processor
    def utility_processor():
        def money_format(value):
            return f'{value:.2f}'

        return dict(money_format=money_format)
# init: flask
app = Flask(__name__)
db = sqlite3.connect("todoapps.db", check_same_thread=False)
curr = db.cursor()
try:
    sql = "Create table username(uid integer Primary Key,urname text, password text)"
    sql_table2 = (
        "Create table todo(id integer Primary Key,ToDoList Text,uid Integer,FOREIGN KEY (uid) REFERENCES "
        "username (uid))")
    curr.execute(sql)
    curr.execute(sql_table2)
    print("success")
except:
    print("sql table already exists")
Bootstrap(app)


# routing
@app.route("/", methods=["GET", "POST"])
def index():
    return render_template("login_page.html")


@app.route("/register", methods=["GET", "POST"])
def register():
    if request.method == "POST":
        username = request.form.get("username")
        password = request.form.get("password")
        con_password = request.form.get("retype_password")
        if password == con_password:
Exemplo n.º 4
0
def create_app():
    new_app = Flask(__name__)
    new_app.config['SECRET_KEY'] = os.getenv('SECRET_KEY')
    CSRFProtect(new_app)
    Bootstrap(new_app)
    return new_app
Exemplo n.º 5
0
from config import Config
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_login import LoginManager
from flask_mail import Mail
from flask_bs4 import Bootstrap
from flask_moment import Moment

app = Flask(__name__)
app.config.from_object(Config)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
login = LoginManager(app)
login.login_view = 'login'
mail = Mail(app)
bootstrap = Bootstrap(app)
moment = Moment(app)

# Emailer and logger for errors in production
if not app.debug:
    if app.config['MAIL_SERVER']:
        auth = None
        if app.config['MAIL_USERNAME'] or app.config['MAIL_PASSWORD']:
            auth = (app.config['MAIL_USERNAME'], app.config['MAIL_PASSWORD'])
        secure = None
        if app.config['MAIL_USE_TLS']:
            secure = ()
        mail_handler = SMTPHandler(
            mailhost=(app.config['MAIL_SERVER'], app.config['MAIL_PORT']),
            fromaddr='no-reply@' + app.config['MAIL_SERVER'],
            toaddrs=app.config['ADMINS'], subject='Microblog Failure',
Exemplo n.º 6
0
from flask import Flask
from flask_bs4 import Bootstrap
from flask_sqlalchemy import SQLAlchemy
from config import Config
from flask_bcrypt import BCrypt

app = Flask(__name__)
bot = Bootstrap(app)
db = SQLAlchemy(app)
bcrypt = BCrypt(app)
app.config.from_object(Config)

from app.routes import *