@@ -8,9 +8,9 @@ module. That is quite simple. Imagine a small application looks like
8
8
this::
9
9
10
10
/yourapplication
11
- / yourapplication.py
11
+ yourapplication.py
12
12
/static
13
- / style.css
13
+ style.css
14
14
/templates
15
15
layout.html
16
16
index.html
@@ -29,9 +29,9 @@ You should then end up with something like that::
29
29
30
30
/yourapplication
31
31
/yourapplication
32
- / __init__.py
32
+ __init__.py
33
33
/static
34
- / style.css
34
+ style.css
35
35
/templates
36
36
layout.html
37
37
index.html
@@ -41,11 +41,36 @@ You should then end up with something like that::
41
41
But how do you run your application now? The naive ``python
42
42
yourapplication/__init__.py `` will not work. Let's just say that Python
43
43
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
45
45
:file: `yourapplication ` folder with the following contents::
46
46
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
49
74
50
75
What did we gain from this? Now we can restructure the application a bit
51
76
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::
77
102
You should then end up with something like that::
78
103
79
104
/yourapplication
80
- /runserver .py
105
+ setup .py
81
106
/yourapplication
82
- / __init__.py
83
- / views.py
107
+ __init__.py
108
+ views.py
84
109
/static
85
- / style.css
110
+ style.css
86
111
/templates
87
112
layout.html
88
113
index.html
0 commit comments