Hello,
I'm developing a web application with Django and we have met a dilemma
about the design.
We were making one template for every screen, but right now we have
detected that some parts of of the screen with the information are repeated
all over the different screens. For example, when coming to show personal
data of a person, you can show also another data concerning that person,
but not personal data (financial data, for instance).
My intuition told me that we should look for a solution in which we could
make small templates that we could compose, combine and concatenate and
that we should also make different views or functions which would return
its own associated template each one.
Thus, *person_data()* would return the rendered template showing the name,
surname, address, etc... and *financial_data()* would return the rendered
template showing the salary, bank account, etc... After that, the desirable
thing would be concatenating both or inserting them in a wider template for
showing all this together.
<html>
...
{# Some html code here #}
...
{# *person_data template* #}
...
...
{# *financial_data template* #}
...
{# Some html code here #}
...
</html>
So as always I made some research on the net and I found:
https://docs.djangoproject.com/en/dev/ref/templates/builtins/#include
a link which describes how to use include for inserting a template file in
another template:
{% include "foo/bar.html" %}
And you can also use a variable from the python function with the path name or
an object with render method:
{% include template_name %}
So we could use all this in this way for combining, concatenating, composing
and operating on templates. We could choose the one which includes the others
and passing it the context for all templates (I suppose, I didn't test
anything). But I don't know if I'm well directed or if this is the best way to
go. I would appreciate some advice.
I also found another interesting thread in stackoverflow talking about this:
http://stackoverflow.com/questions/10985950/how-do-you-insert-a-template-into-another-template
My idea is to have small templates which are used repeatedly in different spots
of the web and composing them in Unix-like style, so I would have small visual
pieces that would be used once and again saving a lot of hours of writing of
code.
Please some advice.
Thanks in advance
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/440ce641-83aa-4cba-b2a9-566cdbc59344%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.