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
+16-29Lines changed: 16 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,36 +44,23 @@ So once again we will create a link to the page, a URL, a view and a template.
44
44
45
45
## Link to a page with the form
46
46
47
-
It's time to open `blog/templates/blog/base.html` in the code editor. In the `div` named `container` inside `page-header``div` tag, we will add a link:
47
+
Before we add the link, we need some icons to use as buttons for the link.
> You can download the whole bootstrap icons [here](https://github.com/twbs/icons/releases/download/v1.1.0/bootstrap-icons-1.1.0.zip). Unzip the file and copy all the svg image files in to a new folder inside `blog/templates/blog/` called `icons`. So that you can access a icon, e.g. pencil-fill.svg using the file path `blog/templates/blog/icons/pencil-fill.svg`
55
50
56
-
Note that we want to call our new view `post_new`. The [svg icon](https://icons.getbootstrap.com/icons/file-earmark-plus/) is provided by the [Bootstrap Icons](https://icons.getbootstrap.com/) and it will display a page icon with plus sign.
51
+
For this tutorial, download [file-earmark-plus.svg](./images/file-earmark-plus.svg) and save it in the folder `blog/templates/blog/icons/`
57
52
58
-
The addition of SVG code for the icon made it look very complicated. So we can try a different approach to achieve the same result.
59
-
60
-
Let's save the svg code in a separate file. Save the following code in the file `blog/templates/blog/icons/add-post.svg`
It's time to open `blog/templates/blog/base.html` in the code editor. Now we can use this icon file inside the base template as follow. In the `div` named `container` inside `page-header``div` tag, we will add a link:
66
54
67
-
Now we can use the file inside the base template as follow.
> Note: You can save the svg file in `blog/static/img/icons/` and use `<img>` tag to display svg icon. But this method requires an extra HTTP request to fetch the file from server. So, it will only increase loading time. But in the proposed method, since `<svg>` tag is HTML, we can simply include it inside HTML file from server itself using `include` directive. This approach reduce the page loading time.
63
+
Note that we want to call our new view `post_new`. The [svg icon](https://icons.getbootstrap.com/icons/file-earmark-plus/) is provided by the [Bootstrap Icons](https://icons.getbootstrap.com/) and it will display a page icon with plus sign. We use a django template directive called `include`. This will inject the file's content in to django template since web browser know how to handle this type of content without any further processing.
77
64
78
65
After editing the line, your HTML file should now look like this:
79
66
@@ -92,7 +79,7 @@ After editing the line, your HTML file should now look like this:
92
79
<divclass="page-header">
93
80
<divclass="container">
94
81
<ahref="{% url 'post_new' %}"class="top-menu">
95
-
{% include './icons/add-post.svg' %}
82
+
{% include './icons/file-earmark-plus.svg' %}
96
83
</a>
97
84
<h1><ahref="/">Django Girls Blog</a></h1>
98
85
</div>
@@ -297,11 +284,11 @@ Django is taking care to validate that all the fields in our form are correct. I
297
284
298
285
Now we know how to add a new post. But what if we want to edit an existing one? This is very similar to what 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 these steps already.)
299
286
300
-
First, let's save the icon which represent edit button. Save the following code in the file `blog/templates/blog/icons/edit-post.svg`
287
+
First, let's save the icon which represent edit button. Download [pencil-fill.svg](./images/pencil-fill.svg) and save it in location `blog/templates/blog/icons/`
0 commit comments