Friday, January 11, 2013

Re: Documentation of app_directories.Loader

Thanks for your feedback. It is exactly the way you suggest. I did not think through what I had done myself (referring to "app_name/*.html" in my views and templates) before posting.

Per-Olof

On Wednesday, January 9, 2013 1:50:17 AM UTC+1, Amirouche wrote:
Héllo Per-Olof,

On Saturday, January 5, 2013 4:17:14 PM UTC+1, Per-Olof Åstrand wrote:
I had a problem interpreting the documentation of app_directories.Loader in https://docs.djangoproject.com/en/dev/ref/templates/api/#loading-templates (I use the dev version of Django). As I read the documentation, I should put the templates for an app in

app_name/templates/*.html


Yes, it should work if you reference the template *without* the app_name for instance 

{% extends "base.html" %}
{% include "footer.html" %}

or in python with «render(request, "base.html", ctx)» but you never render the base html or footer directly so this is dummy example
 
whereas to get it to work, I had to put them in

app_name/templates/app_name/*.html


it only works if you reference the app_name when you call the template for instance «render(request, "app_name/index.html", ctx)» same for include and extends.

It's a convention to avoid clash between templates names, it a way to namespace templates, otherwise you would need to namespace the names of the templates like: «app_name_index.html» which is not nice...


It also seems like it looks for templates in (which I could see from the error message when failing with the first approach)

app_name1/templates/app_name2/*.html

I can see the power of that when having a hierarchy of apps. Am I missing something here?

Per-Olof

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/uKY3IySZbxsJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate