Skip to content

Commit 38f98f6

Browse files
committed
first commit
0 parents  commit 38f98f6

File tree

10 files changed

+103
-0
lines changed

10 files changed

+103
-0
lines changed

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.DS_Store
2+
.env
3+
.flaskenv
4+
*.pyc
5+
*.pyo
6+
dist/
7+
build/
8+
*.egg
9+
*.egg-info/
10+
.tox/
11+
.cache/
12+
.pytest_cache/
13+
.idea/
14+
docs/_build/

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Flask demo
2+
3+
Flask demo for multiple environments and apps.
4+
5+
The environments setting are located in `config.py`

app/__init__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import flask
2+
from flask import Flask
3+
from config import config
4+
from .foo import foo
5+
from .bar import bar
6+
7+
8+
def create_app(env_name):
9+
app = Flask(__name__, static_folder='static', static_url_path='/static') # type: Flask
10+
app.config.from_object(config[env_name])
11+
12+
@app.route('/')
13+
def demo():
14+
return """
15+
this is demo:
16+
<a href="/foo">foo</a>
17+
<a href="/bar">bar</a>
18+
"""
19+
20+
# register foo
21+
app.register_blueprint(foo)
22+
# register bar
23+
app.register_blueprint(bar)
24+
25+
return app
26+

app/bar/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from flask import Blueprint
2+
bar = Blueprint('bar', __name__) # type: Blueprint
3+
from . import views

app/bar/views.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from . import bar
2+
3+
4+
@bar.route('/bar')
5+
def get_index():
6+
return "This is bar!!!"
7+
8+
9+

app/foo/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from flask import Blueprint
2+
foo = Blueprint('foo', __name__) # type: Blueprint
3+
from . import views

app/foo/views.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from . import foo
2+
3+
4+
@foo.route('/foo')
5+
def get_index():
6+
return "This is foo!!!"
7+
8+
9+

config.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import os
2+
3+
4+
class Config:
5+
SECRET_KEY = os.environ.get('SECRET_KEY') or 'xxxx'
6+
FLASK_ADMIN = os.environ.get('ADMIN')
7+
8+
9+
class DevelopmentConfig(Config):
10+
DEBUG = True
11+
12+
13+
class TestingConfig(Config):
14+
TESTING = True
15+
16+
17+
class ProductionConfig(Config):
18+
TEMPLATES_AUTO_RELOAD = True
19+
20+
21+
config = {
22+
'development': DevelopmentConfig,
23+
'testing': TestingConfig,
24+
'production': ProductionConfig,
25+
'default': ProductionConfig
26+
}

manage.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
from app import create_app
3+
4+
# Get the configuration from the environment variable
5+
app = create_app(os.getenv('FLASK_CONFIG') or 'default')
6+
if __name__ == '__main__':
7+
app.run(host='127.0.0.1', port=5002)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Flask

0 commit comments

Comments
 (0)