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: css/README.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,21 +52,21 @@ That's it! Time to see if it works :)
52
52
53
53
First things first: let's create a CSS file now. Create a new folder called `css` inside your `static` folder. Then create a new file called `blog.css` inside this `css` directory. Ready?
54
54
55
-
Time to write some CSS! Open up the `blog.css` file in your code editor.
55
+
Time to write some CSS! Open up the `mysite/static/css/blog.css` file in your code editor.
56
56
57
57
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.
58
58
59
59
But let's do at least a little. Maybe we could change the color of our header? To understand colors, computer use special codes. They start with `#` and are followed by 6 letters and numbers. You can find color codes for example here: http://www.colorpicker.com/
60
60
61
-
In your `blog.css` file you should add following code:
61
+
In your `mysite/static/css/blog.css` file you should add following code:
62
62
63
63
h1 a {
64
64
color: #FCA205;
65
65
}
66
66
67
67
`a` inside of `h1` is the tag we're applying our styles to, and we're telling it to change color to `#FCA205`. Of course, you can put your own color here!
68
68
69
-
Then, we need to also tell our HTML template that we added some CSS. Open the `post_list.html` file and add this line at the very beginning of it:
69
+
Then, we need to also tell our HTML template that we added some CSS. Open the `mysite/blog/templates/blog/post_list.html` file and add this line at the very beginning of it:
70
70
71
71
{% load staticfiles %}
72
72
@@ -88,13 +88,13 @@ Add this to your CSS, save the file and see how it works!
88
88
89
89

90
90
91
-
Maybe we can customize the font in our header? Paste this into your `<head>` in `post_list.html` file:
91
+
Maybe we can customize the font in our header? Paste this into your `<head>` in `mysite/blog/templates/blog/post_list.html` file:
This line will import a font called Lobster from Google Fonts.
96
96
97
-
Now add this line in `blog.css`:
97
+
Now add this line in `mysite/static/css/blog.css`:
98
98
99
99
h1 a {
100
100
color: #FCA205;
@@ -121,7 +121,7 @@ And now add a class `post` to your `div` containing blogposts.
121
121
<p>{{ post.text }}</p>
122
122
</div>
123
123
124
-
All right. We have only one day, so we need to speed things up a little! We can't explain you every little detail about CSS. For now just copy and paste following code into your `blog.css` file:
124
+
All right. We have only one day, so we need to speed things up a little! We can't explain you every little detail about CSS. For now just copy and paste following code into your `mysite/static/css/blog.css` file:
125
125
126
126
.page-header {
127
127
background-color: #ff9400;
@@ -181,7 +181,7 @@ Then also replace this:
181
181
</div>
182
182
{% endfor %}
183
183
184
-
in the `<body>` of your `post_list.html` with this:
184
+
in the `<body>` of your `mysite/blog/templates/blog/post_list.html` with this:
@@ -83,7 +83,7 @@ After saving and refreshing the page `http://127.0.0.1:8000` you will obviously
83
83
84
84
## Url
85
85
86
-
We open `blog/urls.py` and add a line:
86
+
We open `mysite/blog/urls.py` and add a line:
87
87
88
88
url(r'^post/new/$', views.post_new),
89
89
@@ -102,7 +102,7 @@ After refreshing the site, we see an `AttributeError`, since we don't have `post
102
102
103
103
## post_new view
104
104
105
-
Time to open the `blog/views.py` file and add the following lines:
105
+
Time to open the `mysite/blog/views.py` file and add the following lines:
106
106
107
107
from .forms import PostForm
108
108
@@ -116,7 +116,7 @@ To create a new Post form, we need to call `PostForm()` and pass it to the templ
116
116
117
117
## Template
118
118
119
-
We need to create a file `post_edit.html` in the `blog/template/blog` directory. To make a form work we need several things:
119
+
We need to create a file `post_edit.html` in the `mysite/blog/template/blog` directory. To make a form work we need several things:
120
120
121
121
- we need to display the form. We can do that for example with a `{{ form.as_p }}`.
122
122
- the line above have to be wrapped with HTML form tag: <`form method="POST">...</form>`
@@ -149,7 +149,7 @@ The answer is: nothing. We need to do a little bit more work in our view.
149
149
150
150
## Saving the form
151
151
152
-
Open `blog/views.py` once again. Currently all we have in `post_new` view is:
152
+
Open `mysite/blog/views.py` once again. Currently all we have in `post_new` view is:
153
153
154
154
def post_new(request):
155
155
form = PostForm()
@@ -221,7 +221,7 @@ Django is taking care of validating that all fields in our form are correct. Isn
221
221
222
222
Now we know how to add new form. But what if we want to edit an existing one? It is very similar to the thing we just did. Let's create some important things quickly (if you don't understand something - you should ask your coach or look at the previous chapters, since we covered all the steps already).
223
223
224
-
Open `blog/post_detail.html` and add this line:
224
+
Open `mysite/blog/post_detail.html` and add this line:
Copy file name to clipboardExpand all lines: django_models/README.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,7 +77,7 @@ You will notice that a new `blog` folder is created and it contains a number of
77
77
├── tests.py
78
78
└── views.py
79
79
80
-
After creating an application we also need to tell Django that it should use it. We do that in the file `mysite/setting.py`. We need to find `INSTALLED_APPS` and add a line `blog` just above `)`. We should also add `mysite` application (which was created for us when we started a new project in last chapter). So the final product should look like this:
80
+
After creating an application we also need to tell Django that it should use it. We do that in the file `mysite/mysite/setting.py`. We need to find `INSTALLED_APPS` and add a line `blog` just above `)`. We should also add `mysite` application (which was created for us when we started a new project in last chapter). So the final product should look like this:
81
81
82
82
INSTALLED_APPS = (
83
83
'django.contrib.admin',
@@ -94,7 +94,7 @@ After creating an application we also need to tell Django that it should use it.
94
94
95
95
In a file `models.py` we define all objects called `Models` - this is a place in which we will define our blog post.
96
96
97
-
Let's open `blog/models.py`, remove everything from it and write code like this:
97
+
Let's open `mysite/blog/models.py`, remove everything from it and write code like this:
Copy file name to clipboardExpand all lines: django_orm_querysets/README.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ This is exactly what `views` are supposed to do: connect models and templates. I
6
6
7
7
Ok, so how we will achieve it?
8
8
9
-
We need to open our `blog/views.py`. So far `post_list` view looks like this:
9
+
We need to open our `mysite/blog/views.py`. So far `post_list` view looks like this:
10
10
11
11
from django.shortcuts import render
12
12
@@ -54,7 +54,7 @@ The last missing part is to pass the `posts` queryset to the template (we will c
54
54
55
55
In the `render` function we already have parameter with `request` (so everything we receive from the user via internet) and a template file `'blog/post_list.html'`. The last parameter, which looks like this now: `{}` is a place in which we can pass some things to template. We need to give them names (we will stick with `'posts'` right now :)). It should look like this: `{'posts': posts}`.
56
56
57
-
So finally our `views.py` file should look like this:
57
+
So finally our `mysite/blog/views.py` file should look like this:
This line `Post.objects.filter(published_date__isnull=True).order_by('created_date')` makes sure we take only unpublished posts (`published_date__isnull=True`) and order them by `created_date` (`order_by('created_date')`).
26
26
27
-
Ok, the last bit is of course a template! Create a file `blog/templates/blog/post_draft_list.html` and add the following:
27
+
Ok, the last bit is of course a template! Create a file `mysite/blog/templates/blog/post_draft_list.html` and add the following:
28
28
29
29
{% extends 'mysite/base.html' %}
30
30
@@ -48,7 +48,7 @@ Yay! First task is done!
48
48
49
49
It would be nice to have a button on post detail page that will immediatelly publish the post, right?
50
50
51
-
Let's open `blog/template/blog/post_detail.html` and change these lines:
51
+
Let's open `mysite/blog/template/blog/post_detail.html` and change these lines:
52
52
53
53
{% if post.published_date %}
54
54
{{ post.published_date }}
@@ -64,11 +64,11 @@ into these ones:
64
64
65
65
As you noticed, we added `{% else %}` line here. That means, that if the condition from `{% if post.published_date %}` is not fulfilled (so if there is no `published_date`), then we want to do the line `<a class="btn btn-default" href="{% url 'post_publish' pk=post.pk %}">Publish</a>`. Note that we are passing a `pk` variable in the `{% url %}`.
0 commit comments