mirror of https://github.com/docker/docs.git
Docs: update sample application initiation in venv (#15506)
* Docs: update sample application initiation in venv Until now, readers would install 'Flask' on their main system python environment, freeze their entire packages, and grep only the 'Flask' package! So they would be missing all the other dependencies in their requirements file. With this commit, a better practice is followed. First, create a clean virtual environment, then install 'Flask' and freeze everything into the requirements file. Also, I recommend using 'python3 -m pip freeze' instead of 'pip3 freeze' while in the virtual environment. This is because sometimes hidden quirks of 'pip' will ignore the actiavted environment and freeze the entire python packages in the system (e.g. in ArchLinux). * Docs: update python sample testing application In the previous commit, I forgot to update the 'Test the application' section so that the users activate the virtual environment first. This commit fixes that. Co-authored-by: Stefan Scherer <stefan.scherer@docker.com>
This commit is contained in:
parent
f01d1bc739
commit
678d56c1e2
|
@ -28,9 +28,11 @@ Let’s create a simple Python application using the Flask framework that we’l
|
|||
|
||||
```console
|
||||
$ cd /path/to/python-docker
|
||||
$ pip3 install Flask
|
||||
$ pip3 freeze | grep Flask >> requirements.txt
|
||||
$ touch app.py
|
||||
$ python3 -m venv .venv
|
||||
$ source .venv/bin/activate
|
||||
(.venv) $ python3 -m pip install Flask
|
||||
(.venv) $ python3 -m pip freeze > requirements.txt
|
||||
(.venv) $ touch app.py
|
||||
```
|
||||
|
||||
Now, let’s add some code to handle simple web requests. Open this working directory in your favorite IDE and enter the following code into the `app.py` file.
|
||||
|
@ -49,7 +51,9 @@ def hello_world():
|
|||
Let’s start our application and make sure it’s running properly. Open your terminal and navigate to the working directory you created.
|
||||
|
||||
```console
|
||||
$ python3 -m flask run
|
||||
$ cd /path/to/python-docker
|
||||
$ source .venv/bin/activate
|
||||
(.venv) $ python3 -m flask run
|
||||
```
|
||||
|
||||
To test that the application is working properly, open a new browser and navigate to `http://localhost:5000`.
|
||||
|
|
Loading…
Reference in New Issue