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
🐍🌏 Switched to PythonAnywhere for the deploy chapter.
Thanks to Harry Percival for the huge amount of work and
to all the contributors who helped review this chapter.
A copy of the full commit history of this can be found
on the posterity/python-anywhere-rewrite.
Copy file name to clipboardExpand all lines: en/code_editor/README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -34,5 +34,5 @@ The first is that code needs to be **plain text**, and the problem with programs
34
34
35
35
The second reason is that code editors are specialised in editing code, so they can provide helpful features, like highlighting code with colour according to its meaning, or automatically closing quotes for you.
36
36
37
-
We'll see all this in action later. Soon, you'll come to think of your trusty old code editor as one of your favourite tools :)
37
+
We'll see all this in action later. Soon, you'll come to think of your trusty old code editor as one of your favourite tools :)
Copy file name to clipboardExpand all lines: en/css/README.md
+19-22Lines changed: 19 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -33,53 +33,50 @@ Looking nicer already!
33
33
34
34
## Static files in Django
35
35
36
-
Another thing you will learn about today is called __static files__. Static files are all your CSS and images -- files that are not dynamic, so their content doesn't depend on request context and will be the same for every user.
36
+
Finally we will take a closer look at these things we've been calling __static files__. Static files are all your CSS and images -- files that are not dynamic, so their content doesn't depend on the request context and will be the same for every user.
37
37
38
-
CSS is a static file, so in order to customize CSS, we need to first configure static files in Django. You'll only need to do it once. Let's start:
39
38
39
+
### Where to put static files for Django
40
40
41
-
### Configure static files in Django
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`.
42
42
43
-
First, we need to create a directory to store our static files in. Go ahead and create a directory called `static` inside your `djangogirls` directory.
43
+
We do that by creating a folder called `static` inside the blog app:
44
44
45
45
djangogirls
46
-
├─── static
47
-
└─── manage.py
46
+
├── blog
47
+
│ ├── migrations
48
+
│ └── static
49
+
└── mysite
48
50
49
-
Open up the `mysite/settings.py` file, scroll to the bottom of it and add the following lines:
51
+
Django will automatically find any folders called "static" inside any of your apps' folders, and it will be able to use their contents as static files.
50
52
51
-
```python
52
-
STATICFILES_DIRS= (
53
-
os.path.join(BASE_DIR, "static"),
54
-
)
55
-
```
56
-
57
-
This way Django will know where to find your static files.
58
53
59
54
60
55
## Your first CSS file!
61
56
62
57
Let's create a CSS file now, to add your own style to your web-page. Create a new directory called `css` inside your `static` directory. Then create a new file called `blog.css` inside this `css` directory. Ready?
63
58
64
-
static
65
-
└─── css
66
-
blog.css
59
+
djangogirls
60
+
└─── blog
61
+
└─── static
62
+
└─── css
63
+
└─── blog.css
67
64
68
-
Time to write some CSS! Open up the `static/css/blog.css` file in your code editor.
65
+
Time to write some CSS! Open up the `blog/static/css/blog.css` file in your code editor.
69
66
70
67
We won't be going too deep into customizing and learning about CSS here, because it's pretty easy and you can learn it on your own after this workshop. We really recommend doing this [Codeacademy HTML & CSS course](http://www.codecademy.com/tracks/web) to learn everything you need to know about making your websites more pretty with CSS.
71
68
72
69
But let's do at least a little. Maybe we could change the color of our header? To understand colors, computers use special codes. They start with `#` and are followed by 6 letters (A-F) and numbers (0-9). You can find color codes for example here: http://www.colorpicker.com/. You may also use [predefined colors](http://www.w3schools.com/cssref/css_colornames.asp), such as `red` and `green`.
73
70
74
-
In your `static/css/blog.css` file you should add the following code:
71
+
In your `blog/static/css/blog.css` file you should add the following code:
75
72
76
73
```css
77
74
h1a {
78
75
color: #FCA205;
79
76
}
80
77
```
81
78
82
-
`h1 a` is a CSS Selector. This means we're applying our styles to any `a` element inside of an `h1` element (e.g. when we have in code something like: `<h1><a href="">link</a></h1>`). 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!
79
+
`h1 a` is a CSS Selector. This means we're applying our styles to any `a` element inside of an `h1` element (e.g. when we have in code something like: `<h1><a href="">link</a></h1>`). 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!
83
80
84
81
In a CSS file we determine styles for elements in the HTML file. The elements are identified by the element name (i.e. `a`, `h1`, `body`), 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, the following tag may be identified by CSS using the tag name `a`, the class `external_link`, or the id `link_to_wiki_page`:
85
82
@@ -154,7 +151,7 @@ Maybe we can customize the font in our header? Paste this into your `<head>` in
154
151
155
152
This line will import a font called *Lobster* from Google Fonts (https://www.google.com/fonts).
156
153
157
-
Now add the line `font-family: 'Lobster';` in the CSS file `static/css/blog.css` inside the `h1 a` declaration block (the code between the braces `{` and `}`) and refresh the page:
154
+
Now add the line `font-family: 'Lobster';` in the CSS file `blog/static/css/blog.css` inside the `h1 a` declaration block (the code between the braces `{` and `}`) and refresh the page:
158
155
159
156
```css
160
157
h1a {
@@ -188,7 +185,7 @@ And now add a class `post` to your `div` containing a blog post.
188
185
</div>
189
186
```
190
187
191
-
We will now add declaration blocks to different selectors. Selectors starting with `.` relate to classes. There are many great tutorials and explanations about CSS on the Web to help you understand the following code. For now, just copy and paste it into your `djangogirls/static/css/blog.css` file:
188
+
We will now add declaration blocks to different selectors. Selectors starting with `.` relate to classes. There are many great tutorials and explanations about CSS on the Web to help you understand the following code. For now, just copy and paste it into your `blog/static/css/blog.css` file:
0 commit comments