M
M
Maxim Dunayevsky2015-08-21 11:50:33
Django
Maxim Dunayevsky, 2015-08-21 11:50:33

What is the best way to render Django forms - as HTML or create form and widget classes?

Hello!
I caught myself thinking that I was doing a lot of the same type of layout - dialogs for creating elements, lists, etc. In addition, the forms are almost typical.
The entire layout is based on Angular Material and uses such things as ngMessages, md-maxlength, etc. to the fullest.
And so I thought - why not make my own widgets with a redefinition of the render method? Is it advisable? Or is it better not to bother yourself and, as before, just give the laid-out template when Angular asks for it on the client?
PS The question came at a time when, after adding a new field to the model, I had to reverse 3 templates (add a new field and rename one old one).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mintormo, 2015-08-21
@dunmaksim

Move repeating HTML code into a separate template and insert it into the right places with the include tag. If there are several slightly different pieces of code, then apply template inheritance.
1. About include: https://docs.djangoproject.com/en/1.8/ref/template...
2. Template inheritance: https://docs.djangoproject.com/en/1.8/ref/template...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question