You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Branch master set up to track remote branch master from origin.
124
124
```
@@ -130,168 +130,99 @@ Your code is now on GitHub. Go and check it out! You'll find it's in fine compa
130
130
131
131
# Setting up our blog on PythonAnywhere
132
132
133
+
## Sign up for a PythonAnywhere account
134
+
133
135
> **Note** You might have already created a PythonAnywhere account earlier during the install steps – if so, no need to do it again.
134
136
135
137
{% include "/deploy/signup_pythonanywhere.md" %}
136
138
137
139
138
-
## Pulling our code down on PythonAnywhere
140
+
## Configuring our site on PythonAnywhere
139
141
140
-
When you've signed up for PythonAnywhere, you'll be taken to your dashboard or "Consoles" page. Choose the option to start a "Bash" console – that's the PythonAnywhere version of a console, just like the one on your computer.
142
+
Go back to the main [PythonAnywhere Dashboard](https://www.pythonanywhere.com/) by clicking on the logo, and choose the option to start a "Bash" console – that's the PythonAnywhere version of a command line, just like the one on your computer.
141
143
142
-
<imgsrc="images/pythonanywhere_bash_console.png"alt="pointing at Other: Bash in Start a new Console" />
144
+
<imgsrc="images/pythonanywhere_bash_console.png"alt="Pointing at Bash in the New Console section" />
143
145
144
146
> **Note** PythonAnywhere is based on Linux, so if you're on Windows, the console will look a little different from the one on your computer.
145
147
146
-
Let's pull down our code from GitHub and onto PythonAnywhere by creating a "clone" of our repo. Type the following into the console on PythonAnywhere (don't forget to use your GitHub username in place of `<your-github-username>`):
This will pull down a copy of your code onto PythonAnywhere. Check it out by typing `tree my-first-blog`:
148
+
Deploying a web app on PythonAnywhere involves pulling down your code from GitHub, and then configuring PythonAnywhere to recognise it and start serving it as a web application. There are manual ways of doing it, but PythonAnywhere provides a helper tool that will do it all for you. Let's install it first:
That should print out some things like `Collecting pythonanywhere`, and eventually end with a line saying `Successfully installed (...) pythonanywhere- (...)`.
176
156
177
-
### Creating a virtualenv on PythonAnywhere
178
-
179
-
Just like you did on your own computer, you can create a virtualenv on PythonAnywhere. In the Bash console, type:
157
+
Now we run the helper to automatically configure our app from GitHub. Type the following into the console on PythonAnywhere (don't forget to use your GitHub username in place of `<your-github-username>`):
As you watch that running, you'll be able to see what it's doing:
198
165
199
-
> **Note** The `pip install` step can take a couple of minutes. Patience, patience! But if it takes more than five minutes, something is wrong. Ask your coach.
200
-
201
-
<!--TODO: think about using requirements.txt instead of pip install.-->
202
-
203
-
### Creating the database on PythonAnywhere
166
+
- Downloading your code from GitHub
167
+
- Creating a virtualenv on PythonAnywhere, just like the one on your own PC
168
+
- Updating your settings file with some deployment settings
169
+
- Setting up a database on PythonAnywhere using the `manage.py migrate` command
170
+
- Setting up your static files (we'll learn about these later)
171
+
- And configuring PythonAnywhere to serve your web app via its API
204
172
205
-
Here's another thing that's different between your own computer and the server: it uses a different database. So the user accounts and posts can be different on the server and on your computer.
173
+
On PythonAnywhere all those steps are automated, but they're the same steps you would have to go through with any other server provider. The main thing to notice right now is that your database on PythonAnywhere is actually totally separate from your database on your own PC—that means it can have different posts and admin accounts.
206
174
207
-
Just as we did on your own computer, we repeat the step to initialize the database on the server, with `migrate` and `createsuperuser`:
175
+
As a result, just as we did on your own computer, we need to initialize the admin account with `createsuperuser`. PythonAnywhere has automatically activated your virtualenv for you, so all you need to do is run:
Now our code is on PythonAnywhere, our virtualenv is ready, and the database is initialized. We're ready to publish it as a web app!
221
-
222
-
Click back to the PythonAnywhere dashboard by clicking on its logo, and then click on the **Web** tab. Finally, hit **Add a new web app**.
223
-
224
-
After confirming your domain name, choose **manual configuration** (N.B. – *not* the "Django" option) in the dialog. Next choose **Python 3.6**, and click Next to finish the wizard.
225
-
226
-
> **Note** Make sure you choose the "Manual configuration" option, not the "Django" one. We're too cool for the default PythonAnywhere Django setup. ;-)
182
+
Type in the details for your admin user. Best to use the same ones as you're using on your own computer to avoid any confusion, unless you want to make the password on PythonAnywhere more secure.
227
183
184
+
Now, if you like, you can also take a look at your code on PythonAnywhere using `ls`:
228
185
229
-
### Setting the virtualenv
230
-
231
-
You'll be taken to the PythonAnywhere config screen for your webapp, which is where you'll need to go whenever you want to make changes to the app on the server.
In the "Virtualenv" section, click the red text that says "Enter the path to a virtualenv", and enter `/home/<your-PythonAnywhere-username>/my-first-blog/myvenv/`. Click the blue box with the checkmark to save the path before moving on.
236
-
237
-
> **Note** Substitute your own PythonAnywhere username as appropriate. If you make a mistake, PythonAnywhere will show you a little warning.
238
-
239
-
240
-
### Configuring the WSGI file
241
-
242
-
Django works using the "WSGI protocol", a standard for serving websites using Python, which PythonAnywhere supports. The way we configure PythonAnywhere to recognize our Django blog is by editing a WSGI configuration file.
243
-
244
-
Click on the "WSGI configuration file" link (in the "Code" section near the top of the page – it'll be named something like `/var/www/<your-PythonAnywhere-username>_pythonanywhere_com_wsgi.py`), and you'll be taken to an editor.
245
-
246
-
Delete all the contents and replace them with the following:
This file's job is to tell PythonAnywhere where our web app lives and what the Django settings file's name is.
195
+
You can also go to the "Files" tab and navigate around using PythonAnywhere's built-in file browser.
265
196
266
-
The `StaticFilesHandler` is for dealing with our CSS. This is taken care of automatically for you during local development by the `runserver` command. We'll find out a bit more about static files later in the tutorial, when we edit the CSS for our site.
267
197
268
-
Hit **Save** and then go back to the **Web** tab.
198
+
## You are now live!
269
199
270
-
We're all done! Hit the big green **Reload** button and you'll be able to go view your application. You'll find a link to it at the top of the page.
200
+
Your site should now be live on the public Internet! Click through to the PythonAnywhere "Web" tab to get a link to it. You can share this with anyone you want :)
271
201
272
202
273
203
## Debugging tips
274
204
275
-
If you see an error when you try to visit your site, the first place to look for some debugging info is in your **error log**. You'll find a link to this on the PythonAnywhere [Web tab](https://www.pythonanywhere.com/web_app_setup/). See if there are any error messages in there; the most recent ones are at the bottom. Common problems include:
276
205
277
-
- Forgetting one of the steps we did in the console: creating the virtualenv, activating it, installing Django into it, migrating the database.
206
+
If you see an error while running the `pa_autoconfigure_django.py` script, here are a few common causes:
278
207
279
-
- Making a mistake in the virtualenv path on the Web tab – there will usually be a little red error message on there, if there is a problem.
208
+
- Forgetting to create your PythonAnywhere API token.
209
+
- Making a mistake in your GitHub URL
210
+
- If you see an error saying *"Could not find your settings.py"*, it's probably because you didn't manage to add all your files to Git, and/or you didn't push them up to GitHub successfully. Have another look at the Git section above
280
211
281
-
- Making a mistake in the WSGI configuration file – did you get the path to your my-first-blog folder right?
282
212
283
-
- Did you pick the same version of Python for your virtualenv as you did for your web app? Both should be 3.6.
213
+
If you see an error when you try to visit your site, the first place to look for some debugging info is in your **error log**. You'll find a link to this on the PythonAnywhere [Web tab](https://www.pythonanywhere.com/web_app_setup/). See if there are any error messages in there; the most recent ones are at the bottom.
284
214
285
-
There are also some [general debugging tips on the PythonAnywhere wiki](https://www.pythonanywhere.com/wiki/DebuggingImportError).
215
+
There are also some [general debugging tips on the PythonAnywhere help site](http://help.pythonanywhere.com/pages/DebuggingImportError).
286
216
287
217
And remember, your coach is here to help!
288
218
289
219
290
-
# You are live!
220
+
# Check out your site!
291
221
292
222
The default page for your site should say "It worked!", just like it does on your local computer. Try adding `/admin/` to the end of the URL, and you'll be taken to the admin site. Log in with the username and password, and you'll see you can add new Posts on the server.
293
223
294
224
Once you have a few posts created, you can go back to your local setup (not PythonAnywhere). From here you should work on your local setup to make changes. This is a common workflow in web development – make changes locally, push those changes to GitHub, and pull your changes down to your live Web server. This allows you to work and experiment without breaking your live Web site. Pretty cool, huh?
295
225
296
226
297
227
Give yourself a *HUGE* pat on the back! Server deployments are one of the trickiest parts of web development and it often takes people several days before they get them working. But you've got your site live, on the real Internet, just like that!
> **Note** When choosing your username here, bear in mind that your blog's URL will take the form `yourusername.pythonanywhere.com`, so choose either your own nickname or a name for what your blog is all about.
8
+
9
+
## Creating a PythonAnywhere API token
10
+
11
+
This is something you only need to do once. When you've signed up for PythonAnywhere, you'll be taken to your dashboard. Find the link near the top right to your "Accounts" page, then select the tab named "API token", and hit the button that says "Create new API token".
12
+
13
+
<imgsrc="images/pythonanywhere_create_api_token.png"alt="The API token tab on the Accounts page" />
0 commit comments