On Tuesday, January 10, 2012 at 1:13 PM, IgorS wrote:
First of all, thanks a lot to everyone who replied :-)Tom:As i mentioned, i am new to Django and could be missing big parts.Please do not hate me too much for my naivete :-)The approach you suggested regarding the static files seems to bereasonable. Especially considering that the static files willeventually go to a separate server.But I have some doubts regarding the templates. And the doubts comeexactly from that [explicit vs. implicit] perspective. Why not makingit more explicit? I mean to change it in a way that there is no needto relay on the order in which Django searches for the templates. Theorder is defined at the project level and this unnecessarily couplesmy application with the project.
A big reason to keep it the current way, is that typically the project level templates will override app level templates. This let's you create reusable apps and distribute them with default templates, but allow other apps or the project itself to override those templates without having to modify the original app.
The only two places where the templates are referenced are the viewsand other templates (in the "extends" tag). Please correct me if I amwrong. Making it more explicit in the views is simple. E.g., it can bedone like this:template = app_settings.path_to_template('base.html')return render_to_response(template, …)Here app_settings.py is a settings file that stays in theapplication's root folder; and path_to_template is an application-specific function, which returns absolute path to the template (usingos.path and the name of the app's folder).Dealing with the templates that reference other templates (in the"extends" tag) seems a bit trickier... One way that I found is to usea variable in the "extends" tag. But that will require some code inthe application-specific context processor, which in turn will need tobe specified at the project level in settings.py inTEMPLATE_CONTEXT_PROCESSORS.In that case I can do something like this in the templates:{% extends <APP>_TEMPLATES.base %}where base is a key in the <APP>_TEMPLATES dictionary whose valuecontains absolute path to the base.html.This approach seems to be more explicit but also a bit morecomplicated and still depends on the settings at the project level (onthe other hand, having an application-level context processor seems tobe almost inevitable). And yes, my solution seems to be somehow half-baked…Can this problem with the "extends" tag be solved in a more elegantway?Am I digging in a wrong direction? Is it easier to just rely on theDjango's template scanning order and to forget the whole thing?What do you think?Thank you,-igorLooks pretty good, the only thing I would change would be to prefixtemplates and static files with the app name, by placing them inside adirectory named after the app, eg 'app/templates/app/index.html', asthis will avoid conflicts with other templates/static media.CheersTom--You received this message because you are subscribed to the Google Groups "Django users" group.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.
You received this message because you are subscribed to the Google Groups "Django users" group.
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