Skip to content

Commit 1466fff

Browse files
committed
Update to use Python 3
Now installs with apt-get not pip
1 parent ac0e205 commit 1466fff

File tree

1 file changed

+11
-48
lines changed

1 file changed

+11
-48
lines changed

worksheet.md

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,31 @@
22

33
Install the lightweight web framework Flask and set up a basic web server with different pages, using Python, HTML, and CSS.
44

5-
## Installing pip and Flask
5+
## Installing Flask
66

77
First you're going to install the Flask package. Make sure you are connected to the internet, either by Ethernet cable or WiFi before you start.
88

99
1. Start by opening a Terminal window from the taskbar or applications menu:
1010

1111
![Open Terminal window](images/open-terminal.png)
1212

13-
1. Next, you'll need to install `pip` by typing the following command and pressing **Enter** on the keyboard:
13+
1. Now install Flask by typing:
1414

1515
```bash
16-
sudo apt-get install python-pip
16+
sudo apt-get install python3-flask
1717
```
18-
19-
`pip` is a tool for installing Python packages from the Python Packaging Index (PyPi): you can browse packages at [pypi.python.org](https://pypi.python.org/).
20-
21-
1. Now use `pip` to install Flask by typing:
22-
23-
```bash
24-
sudo pip install flask
25-
```
26-
27-
And press **enter**.
2818

2919
## Building a basic Flask web application
3020

3121
Now you're going to set up a basic web application with Flask and Python. You will be able to run a single web page and display some text on a web browser.
3222
33-
1. Return to the Terminal window and create a new folder called `webapp` by typing:
23+
1. Open the **File Manager** and create a new folder for your project.
3424
35-
```bash
36-
mkdir webapp
37-
```
38-
39-
`mkdir` means "make directory": a directory is a folder which can contain files and more folders.
25+
1. Open Python 3 from the main menu.
4026
41-
1. Navigate into this directory by using the `cd` command and pressing **Enter**:
42-
43-
```bash
44-
cd webapp
45-
```
46-
47-
`cd` means "change directory": you use it to enter a folder.
48-
49-
1. Flask applications can be run from a single file, so you need to create the file now using the `touch` command, like this:
50-
51-
```bash
52-
touch app.py
53-
```
54-
55-
This will create a file named `app.py`, in which all our application code will be written.
56-
57-
1. Enter the following command to open this file in the **Python 2** IDE (IDLE), in order to get started writing your web app:
58-
59-
```bash
60-
idle app.py &
61-
```
62-
63-
The ampersand (&) on the end of this command tells it to open IDLE in a new process. Unlike a command like `cd`, this command doesn't finish until you close the IDLE window. Opening IDLE in a new process allows you to enter more commands into the Terminal without quitting IDLE.
27+
1. Open a new window by clicking `File > New file`, and save this as `app.py` inside the project folder you created.
6428
65-
1. An empty window with `app.py` displayed in the title bar will appear. You'll write your application code here and when you run your code, any printed messages or errors will be shown in a Python shell window.
29+
1. You'll write your application code here and when you run your code, any printed messages or errors will be shown in the Python shell window which opened first.
6630

6731
1. Now enter the following lines into the blank `app.py` window:
6832

@@ -81,14 +45,13 @@ Now you're going to set up a basic web application with Flask and Python. You wi
8145
8246
Note here the `host='0.0.0.0'` means the web app will be accessible to any device on the network.
8347
84-
1. Save the file with `Ctrl + S`. Now return to the Terminal window and enter `python app.py` to run the web server.
48+
1. Save the file with `Ctrl + S`. Now return to the Terminal window and enter `python3 app.py` to run the web server.
8549
8650
If everything has been written correctly, you should see an output similar to this:
8751
8852
```
89-
* Restarting with stat
90-
* Debugger is active!
91-
* Debugger pin code: 425-241-775
53+
* Running on http://0.0.0.0:5000/
54+
* Restarting with reloader
9255
```
9356
9457
1. Open the Pi's web browser from the taskbar or application menu and navigate to `http://127.0.0.1:5000/`. You should see a white screen with the words `Hello world`:
@@ -173,7 +136,7 @@ Next, you'll modify your existing routes to return full HTML templates, rather t
173136
174137
Flask will look for `index.html` in a directory called `templates`, in the same directory as the `app.py` file.
175138
176-
1. Save the file. Make sure your web app is still running. If you stopped it, just run `python app.py` from your `webapp` directory.
139+
1. Save the file. Make sure your web app is still running. If you stopped it, just run `python3 app.py` from your `webapp` directory.
177140
178141
1. Reload the route in your web browser (go to the base route at `http://127.0.0.1:5000/`) to see your new HTML template being displayed.
179142

0 commit comments

Comments
 (0)