Hi Martin,
-- You are doing it correctly if you use the
{% include "foo/bar.html" %}method.
I usually try to make my include templates as small as possible and use one or more on a page to try to be as DRY as possible. It tends to make better, smaller code and also it's easier when something changes.
Remember that you can also send information to the includes:
{% include "name_snippet.html" with person="Jane" greeting="Hello" %}This also means that you can have a user page that displays everything about a user, and send the user as a parameter to the include.
Regards,
Andréas
2015-01-04 19:41 GMT+01:00 Martin Torre Castro <madtyn@gmail.com>:
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: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-templateMy 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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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.
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/CALXYUbmCCYw8HY%3D44hLgim%2BWmxENdrLk-H-Y%3DphDzFzXeFHviA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment