Skip to content
Myr

Address #1980 (#2021)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Distinguish between directories and files * Convert larger apps to make use of setup.py - replaces runserver.py with setup.py - example now runs with recommended structure * Fixes a typo and formats the added paragraph

authored by Kyle Lawlor · committed by Markus Unterwaditzer · parent e6f9d2b · 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

1 file+36 added−11 removed

modified:docs/patterns/packages.rst+36 added-11 removed
6 unmodified lines
7module. That is quite simple. Imagine a small application looks like8this::910 /yourapplication11 /yourapplication.py11 yourapplication.py12 /static13 /style.css13 style.css14 /templates15 layout.html16 index.html17 login.html
10 unmodified lines
28You should then end up with something like that::2930 /yourapplication31 /yourapplication32 /__init__.py32 __init__.py33 /static34 /style.css34 style.css35 /templates36 layout.html37 index.html38 login.html
1 unmodified line
4041But how do you run your application now? The naive ``python42yourapplication/__init__.py`` will not work. Let's just say that Python43does not want modules in packages to be the startup file. But that is not44a big problem, just add a new file called :file:`runserver.py` next to the inner44a big problem, just add a new file called :file:`setup.py` next to the inner45:file:`yourapplication` folder with the following contents::4647 from yourapplication import app48 app.run(debug=True)47 from setuptools import setup4849 setup(50 name='yourapplication',51 packages=['yourapplication'],52 include_package_data=True,53 install_requires=[54 'flask',55 ],56 )5758In order to run the application you need to export an environment variable 59that tells Flask where to find the application instance:: 6061 export FLASK_APP=yourapplication6263If you are outside of the project directory make sure to provide the exact 64path to your application directory. Similiarly you can turn on "debug 65mode" with this environment variable:: 6667 export FLASK_DEBUG=true 6869In order to install and run the application you need to issue the following 70commands::7172 pip install -e . 73 flask run7475What did we gain from this? Now we can restructure the application a bit76into multiple modules. The only thing you have to remember is the77following quick checklist:78
22 unmodified lines
101102You should then end up with something like that::103104 /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.html
26 unmodified lines