Merge branch '0.11-maintenance'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parents 9e41eca, 59104db · Browse files · 1 file·+36 added−11 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+36 added−11 removed
- other:+36 added−11 removed
Provenance
- Commit
12008c2- Tree
d3c3c7d- Author
Markus Unterwaditzer <markus@unterwaditzer.net>- Committer
Markus Unterwaditzer <markus@unterwaditzer.net>- Parent 1
9e41eca- Parent 2
59104db
1 file changed+36 added−11 removed
modified:docs/patterns/packages.rst+36 added-11 removed
6 unmodified lines7 module. That is quite simple. Imagine a small application looks like8 this::9 10 /yourapplication11- /yourapplication.py11+ yourapplication.py12 /static13- /style.css13+ style.css14 /templates15 layout.html16 index.html17 login.html10 unmodified lines28 You should then end up with something like that::29 30 /yourapplication31 /yourapplication32- /__init__.py32+ __init__.py33 /static34- /style.css34+ style.css35 /templates36 layout.html37 index.html38 login.html1 unmodified line40 41 But how do you run your application now? The naive ``python42 yourapplication/__init__.py`` will not work. Let's just say that Python43 does not want modules in packages to be the startup file. But that is not44-a big problem, just add a new file called :file:`runserver.py` next to the inner44+a big problem, just add a new file called :file:`setup.py` next to the inner45 :file:`yourapplication` folder with the following contents::46 47- from yourapplication import app48- app.run(debug=True)47+ from setuptools import setup48 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=yourapplication62+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 run74+75 What did we gain from this? Now we can restructure the application a bit76 into multiple modules. The only thing you have to remember is the77 following quick checklist:78 22 unmodified lines101 102 You should then end up with something like that::103 104 /yourapplication80- /runserver.py105+ setup.py106 /yourapplication82- /__init__.py83- /views.py107+ __init__.py108+ views.py109 /static85- /style.css110+ style.css111 /templates112 layout.html113 index.html114 login.html26 unmodified lines