8000 Added code to the ebook about custom field macro · tecladocode/web-dev-bootcamp@42b613e · GitHub
[go: up one dir, main page]

Skip to content

Commit 42b613e

Browse files
committed
Added code to the ebook about custom field macro
1 parent 76f9f8b commit 42b613e

File tree

1 file changed

+16
-1
lines changed
  • curriculum/section14/lectures/14_edit_movies_pre_populate_wtform

1 file changed

+16
-1
lines changed

curriculum/section14/lectures/14_edit_movies_pre_populate_wtform/README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,22 @@ Note that the form pre-population mechanism is the `obj=movie` part.
5454

5555
## Rendering the extended movie form
5656

57-
Let's create the `templates/movie_form.html` template:
57+
First, let's edit the `templates/macros/fields.html` template to add the a new macro in order to render the custom field:
58+
59+
```jinja2
60+
{% macro render_area_field(field) %}
61+
<div class="form__group">
62+
{{ field.label(class_="form__label") }}
63+
{{ field(rows=4, class_="form__field", style="resize: none") }}
64+
65+
{%- for error in field.errors %}
66+
<span class="form__error">{{ error }}</span>
67+
{% endfor %}
68+
</div>
69+
{% endmacro %}
70+
```
71+
72+
And then create the `templates/movie_form.html` template:
5873

5974
```jinja2
6075
{% from "macros/fields.html" import render_text_field, render_area_field %}

0 commit comments

Comments
 (0)
0