Skip to content

Commit 12008c2

Browse files
committed
Merge branch '0.11-maintenance'
2 parents 9e41eca + 59104db commit 12008c2

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

docs/patterns/packages.rst

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ module. That is quite simple. Imagine a small application looks like
88
this::
99

1010
/yourapplication
11-
/yourapplication.py
11+
yourapplication.py
1212
/static
13-
/style.css
13+
style.css
1414
/templates
1515
layout.html
1616
index.html
@@ -29,9 +29,9 @@ You should then end up with something like that::
2929

3030
/yourapplication
3131
/yourapplication
32-
/__init__.py
32+
__init__.py
3333
/static
34-
/style.css
34+
style.css
3535
/templates
3636
layout.html
3737
index.html
@@ -41,11 +41,36 @@ You should then end up with something like that::
4141
But how do you run your application now? The naive ``python
4242
yourapplication/__init__.py`` will not work. Let's just say that Python
4343
does not want modules in packages to be the startup file. But that is not
44-
a big problem, just add a new file called :file:`runserver.py` next to the inner
44+
a big problem, just add a new file called :file:`setup.py` next to the inner
4545
:file:`yourapplication` folder with the following contents::
4646

47-
from yourapplication import app
48-
app.run(debug=True)
47+
from setuptools import setup
48+
49+
setup(
50+
name='yourapplication',
51+
packages=['yourapplication'],
52+
include_package_data=True,
53+
install_requires=[
54+
'flask',
55+
],
56+
)
57+
58+
In order to run the application you need to export an environment variable
59+
that tells Flask where to find the application instance::
60+
61+
export FLASK_APP=yourapplication
62+
63+
If you are outside of the project directory make sure to provide the exact
64+
path to your application directory. Similiarly you can turn on "debug
65+
mode" with this environment variable::
66+
67+
export FLASK_DEBUG=true
68+
69+
In order to install and run the application you need to issue the following
70+
commands::
71+
72+
pip install -e .
73+
flask run
4974

5075
What did we gain from this? Now we can restructure the application a bit
5176
into multiple modules. The only thing you have to remember is the
@@ -77,12 +102,12 @@ And this is what :file:`views.py` would look like::
77102
You should then end up with something like that::
78103

79104
/yourapplication
80-
/runserver.py
105+
setup.py
81106
/yourapplication
82-
/__init__.py
83-
/views.py
107+
__init__.py
108+
views.py
84109
/static
85-
/style.css
110+
style.css
86111
/templates
87112
layout.html
88113
index.html

0 commit comments

Comments
 (0)