Skip to content
Myr

layout.rst

This file

Path

docs/tutorial/layout.rst

110 lines · 2.9 KiB

Last changed by

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

History of this file

Take it

The walk stopped after 200 commits: lines older than 8bfce88 point at it.

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

lines 1–43why, one step back
1Project Layout
2==============34Create a project directory and enter it:56.. code-block:: none78 $ mkdir flask-tutorial9 $ cd flask-tutorial1011Then follow the :doc:`installation instructions </installation>` to set12up a Python virtual environment and install Flask for your project.1314The tutorial will assume you're working from the ``flask-tutorial``15directory from now on. The file names at the top of each code block are16relative to this directory.1718----1920A Flask application can be as simple as a single file.2122.. code-block:: python23 :caption: ``hello.py``2425 from flask import Flask2627 app = Flask(__name__)282930 @app.route('/')31 def hello():32 return 'Hello, World!'3334However, as a project gets bigger, it becomes overwhelming to keep all35the code in one file. Python projects use *packages* to organize code36into multiple modules that can be imported where needed, and the37tutorial will do this as well.3839The project directory will contain:4041* ``flaskr/``, a Python package containing your application code and42 files.43* ``tests/``, a directory containing test modules.

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

line 44why, one step back
44* ``.venv/``, a Python virtual environment where Flask and other

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

lines 45–59why, one step back
45 dependencies are installed.
46* Installation files telling Python how to install your project.47* Version control config, such as `git`_. You should make a habit of48 using some type of version control for all your projects, no matter49 the size.50* Any other project files you might add in the future.5152.. _git: https://git-scm.com/5354By the end, your project layout will look like this:5556.. code-block:: none5758 /home/user/Projects/flask-tutorial59 ├── flaskr/

Merge branch '2.0.x'David Lordbefore adoptionedac7e3

lines 60–75why, one step back
60 │ ├── __init__.py
61 │ ├── db.py62 │ ├── schema.sql63 │ ├── auth.py64 │ ├── blog.py65 │ ├── templates/66 │ │ ├── base.html67 │ │ ├── auth/68 │ │ │ ├── login.html69 │ │ │ └── register.html70 │ │ └── blog/71 │ │ ├── create.html72 │ │ ├── index.html73 │ │ └── update.html74 │ └── static/75 │ └── style.css

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

line 76why, one step back
76 ├── tests/

Merge branch '2.0.x'David Lordbefore adoptionedac7e3

lines 77–82why, one step back
77 │ ├── conftest.py
78 │ ├── data.sql79 │ ├── test_factory.py80 │ ├── test_db.py81 │ ├── test_auth.py82 │ └── test_blog.py

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

lines 83–84why, one step back
83 ├── .venv/
84 ├── pyproject.toml

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

lines 85–94why, one step back
85 └── MANIFEST.in
8687If you're using version control, the following files that are generated88while running your project should be ignored. There may be other files89based on the editor you use. In general, ignore files that you didn't90write. For example, with git:9192.. code-block:: none93 :caption: ``.gitignore``94

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

line 95why, one step back
95 .venv/

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

lines 96–110why, one step back
96
97 *.pyc98 __pycache__/99100 instance/101102 .pytest_cache/103 .coverage104 htmlcov/105106 dist/107 build/108 *.egg-info/109110Continue to :doc:`factory`.