| 1 |
Flaskr |
| 2 |
====== |
| 3 |
|
| 4 |
The basic blog app built in the Flask `tutorial`_, modified to use |
| 5 |
Flask-SQLAlchemy instead of plain SQL. |
| 6 |
|
| 7 |
.. _tutorial: https://flask.palletsprojects.com/tutorial/ |
| 8 |
|
| 9 |
|
| 10 |
Install |
| 11 |
------- |
| 12 |
|
| 13 |
**Be sure to use the same version of the code as the version of the docs |
| 14 |
you're reading.** You probably want the latest tagged version, but the |
| 15 |
default Git version is the main branch. |
| 16 |
|
| 17 |
.. code-block:: text |
| 18 |
|
| 19 |
# clone the repository |
| 20 |
$ git clone https://github.com/pallets/flask-sqlalchemy |
| 21 |
$ cd flask-sqlalchemy/examples/flaskr |
| 22 |
# checkout the correct version |
| 23 |
$ git checkout correct-version-tag |
| 24 |
|
| 25 |
Create a virtualenv and activate it: |
| 26 |
|
| 27 |
.. code-block:: text |
| 28 |
|
| 29 |
$ python3 -m venv venv |
| 30 |
$ . venv/bin/activate |
| 31 |
|
| 32 |
Or on Windows cmd: |
| 33 |
|
| 34 |
.. code-block:: text |
| 35 |
|
| 36 |
$ py -3 -m venv venv |
| 37 |
$ venv\Scripts\activate.bat |
| 38 |
|
| 39 |
Install Flaskr: |
| 40 |
|
| 41 |
.. code-block:: text |
| 42 |
|
| 43 |
$ pip install -e . |
| 44 |
|
| 45 |
Or if you are using the main branch, install Flask-SQLAlchemy from |
| 46 |
source before installing Flaskr: |
| 47 |
|
| 48 |
.. code-block:: text |
| 49 |
|
| 50 |
$ pip install -e ../.. |
| 51 |
$ pip install -e . |
| 52 |
|
| 53 |
|
| 54 |
Run |
| 55 |
--- |
| 56 |
|
| 57 |
.. code-block:: text |
| 58 |
|
| 59 |
$ export FLASK_APP=flaskr |
| 60 |
$ export FLASK_ENV=development |
| 61 |
$ flask init-db |
| 62 |
$ flask run |
| 63 |
|
| 64 |
Or on Windows cmd: |
| 65 |
|
| 66 |
.. code-block:: text |
| 67 |
|
| 68 |
> set FLASK_APP=flaskr |
| 69 |
> set FLASK_ENV=development |
| 70 |
> flask init-db |
| 71 |
> flask run |
| 72 |
|
| 73 |
Open http://127.0.0.1:5000 in a browser. |
| 74 |
|
| 75 |
|
| 76 |
Test |
| 77 |
---- |
| 78 |
|
| 79 |
.. code-block:: text |
| 80 |
|
| 81 |
$ pip install -e '.[test]' |
| 82 |
$ python3 -m pytest |
| 83 |
|
| 84 |
Run with coverage report: |
| 85 |
|
| 86 |
.. code-block:: text |
| 87 |
|
| 88 |
$ coverage run -m pytest |
| 89 |
$ coverage report |
| 90 |
$ coverage html # open htmlcov/index.html in a browser |