Skip to content
Myr

setuptools.rst

This file

Path

docs/tutorial/setuptools.rst

89 lines · 3.0 KiB

Last changed by

Merge branch '0.11-maintenance'David Lordbefore adoption633b13e

History of this file

Take it

Merge branch '0.11-maintenance'David Lordbefore adoption633b13e

lines 1–89why, one step back
1.. _tutorial-setuptools:
23Step 3: Installing flaskr with setuptools4=========================================56Flask is now shipped with built-in support for `Click`_. Click provides7Flask with enhanced and extensible command line utilities. Later in this8tutorial you will see exactly how to extend the ``flask`` command line9interface (CLI).1011A useful pattern to manage a Flask application is to install your app12using `setuptools`_. This involves creating a :file:`setup.py`13in the projects root directory. You also need to add an empty14:file:`__init__.py` file to make the :file:`flaskr/flaskr` directory15a package. The code structure at this point should be::1617 /flaskr18 /flaskr19 __init__.py20 /static21 /templates22 setup.py2324The content of the ``setup.py`` file for ``flaskr`` is:2526.. sourcecode:: python2728 from setuptools import setup2930 setup(31 name='flaskr',32 packages=['flaskr'],33 include_package_data=True,34 install_requires=[35 'flask',36 ],37 )3839When using setuptools, it is also necessary to specify any special files40that should be included in your package (in the :file:`MANIFEST.in`).41In this case, the static and templates directories need to be included,42as well as the schema. Create the :file:`MANIFEST.in` and add the43following lines::4445 graft flaskr/templates46 graft flaskr/static47 include flaskr/schema.sql4849At this point you should be able to install the application. As usual, it50is recommended to install your Flask application within a `virtualenv`_.51With that said, go ahead and install the application with::5253 pip install --editable .5455.. note:: The above installation command assumes that it is run within the56 projects root directory, `flaskr/`. Also, the `editable` flag allows57 editing source code without having to reinstall the Flask app each time58 you make changes.5960With that out of the way, you should be able to start up the application.61Do this with the following commands::6263 export FLASK_APP=flaskr.flaskr64 export FLASK_DEBUG=165 flask run6667(In case you are on Windows you need to use `set` instead of `export`).68The :envvar:`FLASK_DEBUG` flag enables or disables the interactive debugger.69*Never leave debug mode activated in a production system*, because it will70allow users to execute code on the server!7172You will see a message telling you that server has started along with73the address at which you can access it.7475When you head over to the server in your browser, you will get a 404 error76because we don't have any views yet. That will be addressed a little later,77but first, you should get the database working.7879.. admonition:: Externally Visible Server8081 Want your server to be publicly available? Check out the82 :ref:`externally visible server <public-server>` section for more83 information.8485Continue with :ref:`tutorial-dbcon`.8687.. _Click: http://click.pocoo.org88.. _setuptools: https://setuptools.readthedocs.io89.. _virtualenv: https://virtualenv.pypa.io