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/django_forms/README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -128,7 +128,7 @@ We need to create a file `post_edit.html` in the `blog/templates/blog` directory
128
128
- we have to display the form. We can do that for example with a simple `{{ form.as_p }}`.
129
129
- the line above needs to be wrapped with an HTML form tag: `<form method="POST">...</form>`
130
130
- we need a `Save` button. We do that with an HTML button: `<button type="submit">Save</button>`
131
-
- and finally just after the opening `<form ...>` tag we need to add `{% csrf_token %}`. This is very important, since it makes your forms secure! Django will complain if you forget about this bit if you try to save the form:
131
+
- and finally just after the opening `<form ...>` tag we need to add `{% raw %}{% csrf_token %}{% endraw %}`. This is very important, since it makes your forms secure! Django will complain if you forget about this bit if you try to save the form:
Copy file name to clipboardExpand all lines: en/extend_your_application/README.md
+42-34Lines changed: 42 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,26 +11,30 @@ We already have a `Post` model, so we don't need to add anything to `models.py`.
11
11
## Create a link in the template
12
12
13
13
We will start with adding a link inside `blog/templates/blog/post_list.html` file. So far it should look like:
14
+
```html
15
+
{% extends 'blog/base.html' %}
14
16
15
-
{% extends 'blog/base.html' %}
16
-
17
-
{% block content %}
18
-
{% for post in posts %}
19
-
<div class="post">
20
-
<div class="date">
21
-
{{ post.published_date }}
22
-
</div>
23
-
<h1><a href="">{{ post.title }}</a></h1>
24
-
<p>{{ post.text|linebreaks }}</p>
17
+
{% block content %}
18
+
{% for post in posts %}
19
+
<divclass="post">
20
+
<divclass="date">
21
+
{{ post.published_date }}
25
22
</div>
26
-
{% endfor %}
27
-
{% endblock content %}
23
+
<h1><ahref="">{{ post.title }}</a></h1>
24
+
<p>{{ post.text|linebreaks }}</p>
25
+
</div>
26
+
{% endfor %}
27
+
{% endblock content %}
28
28
29
-
We want to have a link to a post detail page on the post's title. Let's change `<h1><a href="">{{ post.title }}</a></h1>` into a link:
29
+
```
30
+
31
+
{% raw %}We want to have a link to a post detail page on the post's title. Let's change `<h1><a href="">{{ post.title }}</a></h1>` into a link:{% endraw %}
Time to explain the mysterious `{% url 'blog.views.post_detail' pk=post.pk %}`. As you might suspect, the `{% %}` notation means that we are using Django template tags. This time we will use one that will create a URL for us!
37
+
{% raw %}Time to explain the mysterious `{% url 'blog.views.post_detail' pk=post.pk %}`. As you might suspect, the `{% %}` notation means that we are using Django template tags. This time we will use one that will create a URL for us!{% endraw %}
34
38
35
39
`blog.views.post_detail` is a path to a `post_detail`*view* we want to create. Please note: `blog` is the name of our application (the directory `blog`), `views` is from the name of the `views.py` file and the last bit - `post_detail` - is the name of the *view*.
36
40
@@ -44,13 +48,15 @@ Let's create a URL in `urls.py` for our `post_detail` *view*!
44
48
45
49
We want to create a URL to point Django to a *view* called `post_detail`, that will show an entire blog post. Add the line `url(r'^post/(?P<pk>[0-9]+)/$', views.post_detail),` to the `blog/urls.py` file. It should look like this:
That one looks scary, but no worries - we will explain it for you:
56
62
- it starts with `^` again -- "the beginning"
@@ -113,23 +119,25 @@ We will create a file in `blog/templates/blog` called `post_detail.html`.
113
119
114
120
It will look like this:
115
121
116
-
{% extends 'blog/base.html' %}
122
+
```html
123
+
{% extends 'blog/base.html' %}
117
124
118
-
{% block content %}
119
-
<div class="post">
120
-
{% if post.published_date %}
121
-
<div class="date">
122
-
{{ post.published_date }}
123
-
</div>
124
-
{% endif %}
125
-
<h1>{{ post.title }}</h1>
126
-
<p>{{ post.text|linebreaks }}</p>
127
-
</div>
128
-
{% endblock %}
125
+
{% block content %}
126
+
<divclass="post">
127
+
{% if post.published_date %}
128
+
<divclass="date">
129
+
{{ post.published_date }}
130
+
</div>
131
+
{% endif %}
132
+
<h1>{{ post.title }}</h1>
133
+
<p>{{ post.text|linebreaks }}</p>
134
+
</div>
135
+
{% endblock %}
136
+
```
129
137
130
138
Once again we are extending `base.html`. In the `content` block we want to display a post's published_date (if it exists), title and text. But we should discuss some important things, right?
131
139
132
-
`{% if ... %} ... {% endif %}` is a template tag we can use when we want to check something (remember `if ... else ..` from __Introduction to Python__ chapter?). In this scenario we want to check if a post's `published_date` is not empty.
140
+
{% raw %}`{% if ... %} ... {% endif %}` is a template tag we can use when we want to check something (remember `if ... else ..` from __Introduction to Python__ chapter?). In this scenario we want to check if a post's `published_date` is not empty.{% endraw %}
133
141
134
142
Ok, we can refresh our page and see if `Page not found` is gone now.
Copy file name to clipboardExpand all lines: en/template_extending/README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,7 +97,7 @@ And now add this line to the beginning of the file:
97
97
98
98
{% extends 'blog/base.html' %}
99
99
100
-
It means that we're now extending the `base.html` template in `post_list.html`. Only one thing left: put everything (except the line we just added) between `{% block content %}` and `{% endblock content %}`. Like this:
100
+
{% raw %}It means that we're now extending the `base.html` template in `post_list.html`. Only one thing left: put everything (except the line we just added) between `{% block content %}` and `{% endblock content %}`. Like this:{% endraw %}
0 commit comments