Skip to content
Myr

layout.rst

This file

Path

docs/tutorial/layout.rst

110 lines · 2.9 KiB

Last changed by

Add prefix for all commands in documentation (#2877)Grey Libefore adoption21b0aa6

History of this file

Take it

The walk stopped after 200 commits: lines older than 35afec3 point at it.

Merge branch '1.0-maintenance'David Lordbefore adoption35afec3

lines 1–7why, one step back
1Project Layout
2==============34Create a project directory and enter it:56.. code-block:: none7

Add prefix for all commands in documentation (#2877)Grey Libefore adoption21b0aa6

lines 8–9why, one step back
8 $ mkdir flask-tutorial
9 $ cd flask-tutorial

Merge branch '1.0-maintenance'David Lordbefore adoption35afec3

lines 10–33why, one step back
10
11Then 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!'33

Merge pull request #2850 from billfienberg/patch-1David Lordbefore adoption06b189b

line 34why, one step back
34However, as a project gets bigger, it becomes overwhelming to keep all

Merge branch '1.0-maintenance'David Lordbefore adoption35afec3

lines 35–110why, one step back
35the code in one file. Python projects use *packages* to organize code
36into 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.44* ``venv/``, a Python virtual environment where Flask and other45 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/60 │   ├── __init__.py61 │   ├── 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.css76 ├── tests/77 │   ├── conftest.py78 │   ├── data.sql79 │   ├── test_factory.py80 │   ├── test_db.py81 │  ├── test_auth.py82 │  └── test_blog.py83 ├── venv/84 ├── setup.py85 └── MANIFEST.in8687If 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``9495 venv/9697 *.pyc98 __pycache__/99100 instance/101102 .pytest_cache/103 .coverage104 htmlcov/105106 dist/107 build/108 *.egg-info/109110Continue to :doc:`factory`.