-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
58 lines (48 loc) · 1.97 KB
/
app.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
from flask import Flask, redirect, url_for
from models import db, login, PageModel, SettingsModel
import config
from setup.routes import setup
from admin.routes import admin
from website.routes import website
app = Flask(__name__)
# Register blueprints
app.register_blueprint(setup)
app.register_blueprint(admin)
app.register_blueprint(website)
# Configure database
app.config['SQLALCHEMY_DATABASE_URI'] = config.SQLALCHEMY_DATABASE_URI
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.secret_key = config.secret_key
db.init_app(app)
login.init_app(app)
login.login_view = 'admin.login'
@app.before_first_request
def create_table():
db.create_all()
# add an home page entry to pages table
if PageModel.query.filter_by(name='Home Page').first() is None:
page = PageModel(name='Home Page', url='',
content='<h1 class="title">Welcome to the website!</h1>'
'<p>This is the home page.</p>'
'<a href="/admin/pages">Manage pages</a>')
db.session.add(page)
db.session.commit()
# add default settings if they don't exist
if SettingsModel.query.filter_by(key='website_name').first() is None:
settings = SettingsModel(key='website_name', value='My Website')
db.session.add(settings)
db.session.commit()
if SettingsModel.query.filter_by(key='home_page').first() is None:
settings = SettingsModel(key='home_page', value='1')
db.session.add(settings)
db.session.commit()
if SettingsModel.query.filter_by(key='blog_page').first() is None:
settings = SettingsModel(key='blog_page', value='1')
db.session.add(settings)
db.session.commit()
if SettingsModel.query.filter_by(key='display_navigation_bar').first() is None:
settings = SettingsModel(key='display_navigation_bar', value='true')
db.session.add(settings)
db.session.commit()
if __name__ == '__main__':
app.run()