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
Copy file name to clipboardExpand all lines: en/css/README.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,7 @@ Finally we will take a closer look at these things we've been calling __static f
38
38
39
39
### Where to put static files for Django
40
40
41
-
As you saw when we ran `collectstatic` on the server, Django already knows where to find the static files for the built-in "admin" app. Now we just need to add some static files for our own app, `blog`.
41
+
Django already knows where to find the static files for the built-in "admin" app. Now we just need to add some static files for our own app, `blog`.
42
42
43
43
We do that by creating a folder called `static` inside the blog app:
44
44
@@ -66,7 +66,7 @@ Time to write some CSS! Open up the `blog/static/css/blog.css` file in your code
66
66
67
67
We won't be going too deep into customizing and learning about CSS here. It's pretty easy and you can learn it on your own after this workshop. There is a recommendation for a free course to learn more at the end of this page.
68
68
69
-
But let's do at least a little. Maybe we could change the color of our header?
69
+
But let's do at least a little. Maybe we could change the color of our header?
70
70
To understand colors, computers use special codes. These codes start with `#` followed by 6 letters (A-F) and numbers (0-9). For example, the code for blue is `#0000FF`. You can find the color codes for many colors here: http://www.colorpicker.com/. You may also use [predefined colors](http://www.w3schools.com/cssref/css_colornames.asp), such as `red` and `green`.
71
71
72
72
In your `blog/static/css/blog.css` file you should add the following code:
@@ -79,7 +79,7 @@ h1 a {
79
79
80
80
`h1 a` is a CSS Selector. This means we're applying our styles to any `a` element inside of an `h1` element. So when we have something like: `<h1><a href="">link</a></h1>` the `h1 a` style will apply. In this case, we're telling it to change its color to `#FCA205`, which is orange. Of course, you can put your own color here!
81
81
82
-
In a CSS file we determine styles for elements in the HTML file. The first way we identify elements is with the element name. You might remember these as tags from the HTML section. Things like `a`, `h1`, and `body` are all examples of element names.
82
+
In a CSS file we determine styles for elements in the HTML file. The first way we identify elements is with the element name. You might remember these as tags from the HTML section. Things like `a`, `h1`, and `body` are all examples of element names.
83
83
We also identify elements by the attribute `class` or the attribute `id`. Class and id are names you give the element by yourself. Classes define groups of elements, and ids point to specific elements. For example, you could identify the following tag by using the tag name `a`, the class `external_link`, or the id `link_to_wiki_page`:
84
84
85
85
```html
@@ -94,13 +94,13 @@ Then, we need to also tell our HTML template that we added some CSS. Open the `b
94
94
{% load staticfiles %}
95
95
```
96
96
97
-
We're just loading static files here :).
97
+
We're just loading static files here :).
98
98
Between the `<head>` and `</head>`, after the links to the Bootstrap CSS files add this line:
The browser reads the files in the order they're given, so we need to make sure this is in the right place. Otherwise the code in our file may override code in Bootstrap files.
103
+
The browser reads the files in the order they're given, so we need to make sure this is in the right place. Otherwise the code in our file may override code in Bootstrap files.
104
104
We just told our template where our CSS file is located.
105
105
106
106
Your file should now look like this:
@@ -276,10 +276,10 @@ Save those files and refresh your website.
276
276
277
277

278
278
279
-
Woohoo! Looks awesome, right?
280
-
Look at the code we just pasted to find the places where we added classes in the HTML and used them in the CSS. Where would you make the change if you wanted the date to be turquoise?
279
+
Woohoo! Looks awesome, right?
280
+
Look at the code we just pasted to find the places where we added classes in the HTML and used them in the CSS. Where would you make the change if you wanted the date to be turquoise?
281
281
282
-
Don't be afraid to tinker with this CSS a little bit and try to change some things. Playing with the CSS can help you understand what the different things are doing. If you break something, don't worry, you can always undo it!
282
+
Don't be afraid to tinker with this CSS a little bit and try to change some things. Playing with the CSS can help you understand what the different things are doing. If you break something, don't worry, you can always undo it!
283
283
284
284
We really recommend taking this free online [Codeacademy HTML & CSS course](http://www.codecademy.com/tracks/web). It can help you learn all about making your websites prettier with CSS.
<!--TODO: think about using requirements.txt instead of pip install.-->
180
180
181
181
182
-
### Collecting static files.
183
-
184
-
Were you wondering what the "whitenoise" thing was? It's a tool for serving so-called "static files". Static files are the files that don't regularly change or don't run programming code, such as HTML or CSS files. They work differently on servers compared to on our own computer and we need a tool like "whitenoise" to serve them.
185
-
186
-
We'll find out a bit more about static files later in the tutorial, when we edit the CSS for our site.
187
-
188
-
For now we just need to run an extra command called `collectstatic`, on the server. It tells Django to gather up all the static files it needs on the server. At the moment these are mostly files that make the admin site look pretty.
189
-
190
-
(myvenv) $ python manage.py collectstatic
191
-
192
-
You have requested to collect static files at the destination
193
-
location as specified in your settings:
194
-
195
-
/home/edith/my-first-blog/static
196
-
197
-
This will overwrite existing files!
198
-
Are you sure you want to do this?
199
-
200
-
Type 'yes' to continue, or 'no' to cancel: yes
201
-
202
-
Type "yes", and away it goes! Don't you love making computers print out pages and pages of impenetrable text? I always make little noises to accompany it. Brp, brp brp...
62 static files copied to '/home/edith/my-first-blog/static'.
210
-
211
-
212
182
### Creating the database on PythonAnywhere
213
183
214
184
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.
@@ -227,7 +197,7 @@ We can initialise the database on the server just like we did the one on your ow
227
197
228
198
## Publishing our blog as a web app
229
199
230
-
Now our code is on PythonAnywhere, our virtualenv is ready, the static files are collected, and the database is initialised. We're ready to publish it as a web app!
200
+
Now our code is on PythonAnywhere, our virtualenv is ready, and the database is initialised. We're ready to publish it as a web app!
231
201
232
202
Click back to the PythonAnywhere dashboard by clicking on its logo, and go click on the **Web** tab. Finally, hit **Add a new web app**.
> **Note** Don't forget to substitute in your own username where it says `<your-username>`
275
-
> **Note** In line three, we make sure Pyhthon anywhere knows how to find our application. It is very important that this path name is correct, and especially that there are no extra spaces here. Otherwise you will see an "ImportError" in the error log.
245
+
> **Note** In line three, we make sure Python anywhere knows how to find our application. It is very important that this path name is correct, and especially that there are no extra spaces here. Otherwise you will see an "ImportError" in the error log.
246
+
247
+
This file's job is to tell PythonAnywhere where our web app lives and what the Django settings file's name is.
276
248
277
-
This file's job is to tell PythonAnywhere where our web app lives and what the Django settings file's name is. It also sets up the "whitenoise" static files tool.
249
+
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.
278
250
279
251
Hit **Save** and then go back to the **Web** tab.
280
252
@@ -285,7 +257,7 @@ We're all done! Hit the big green **Reload** button and you'll be able to go vie
285
257
286
258
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:
287
259
288
-
- Forgetting one of the steps we did in the console: creating the virtualenv, activating it, installing Django into it, running collectstatic, migrating the database.
260
+
- Forgetting one of the steps we did in the console: creating the virtualenv, activating it, installing Django into it, migrating the database.
289
261
290
262
- 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.
Copy file name to clipboardExpand all lines: en/html/README.md
-2Lines changed: 0 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -182,8 +182,6 @@ $ cd ~/my-first-blog
182
182
$ source myvenv/bin/activate
183
183
(myvenv)$ git pull
184
184
[...]
185
-
(myvenv)$ python manage.py collectstatic
186
-
[...]
187
185
```
188
186
189
187
And watch your code get downloaded. If you want to check that it's arrived, you can hop over to the **Files tab** and view your code on PythonAnywhere.
0 commit comments