On 10/30/2011 12:41 PM, SmileyChris wrote:
> Take a read through this section of the docs:
> https://docs.djangoproject.com/en/1.3/ref/templates/api/#loading-templates
Yes, that's what I was reading.
> Specifically, those templates are found via the app_directories.Loader.
> So you'd run loader.get_template('admin/base.html') to get that
> template. The reason that it's in a subdirectory is to avoid conflicts
> with other applications (since they may want to use their own
> 'base.html' template.
So, my setting TEMPLATE_DIRS here to the actual subdirectory would not work?
TEMPLATE_DIRS=('C:/Python26/Lib/site-packages/django/contrib/admin/templates/admin')
I used this as an example to point to some templates that are known to
work, rather than point to my own templates that don't work either. If I
go into the Django code and print out the directory that's being
searched, I see the correct directory there, so I don't know why things
are failing. Maybe I'm just not instantiating things correctly?
In any case, I tried your suggestion, but still no luck:
>>> loader.get_template('admin/base.html')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "django/template/loader.py", line 164, in get_template
template, origin = find_template(template_name)
File "django/template/loader.py", line 145, in find_template
raise TemplateDoesNotExist(name)
django.template.base.TemplateDoesNotExist: admin/base.html
(I also tried without manually setting TEMPLATE_DIRS, but just ran
django.conf.settings.configure(), still to no avail.)
Anyone, any ideas? I'm completely new to Django, but I've not been
working in Python lately either, so it could just be a Python mistake on
my part.
- Stefan
Hi Django folks -
Any ideas?
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to
django-users...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
TEMPLATE_DIRS=('C:/Python26/Lib/site-packages/django/contrib/admin/templates')
Thanks for the suggestion. I don't see much difference on my system here
though...
C:\Program Files (x86)\Microsoft Visual Studio 8\VC>c:\Python26\python.exe
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import django.template
>>>
django.conf.settings.configure(TEMPLATE_DIRS=('C:/Python26/Lib/site-packages/django/contrib/admin/templates'),TEMPLATE_DEBUG=True,
DEBUG=True)
>>> import django.template.loader as loader
>>> loader.get_template("base.html")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Python26\lib\site-packages\django\template\loader.py", line
157, in get_template
template, origin = find_template(template_name)
File "c:\Python26\lib\site-packages\django\template\loader.py", line
138, in find_template
raise TemplateDoesNotExist(name)
django.template.base.TemplateDoesNotExist: base.html
>>> loader.get_template("admin/base.html")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Python26\lib\site-packages\django\template\loader.py", line
157, in get_template
template, origin = find_template(template_name)
File "c:\Python26\lib\site-packages\django\template\loader.py", line
138, in find_template
raise TemplateDoesNotExist(name)
django.template.base.TemplateDoesNotExist: admin/base.html
Has anyone here used the template system successfully without using all
of Django?
Parentheses do not the tuple make. It's the comma. An expression
surrounded by parentheses is just the expression, so you're trying to
use each letter of your setting as a directory, I believe.
I take it you're not using the app directories loader?
Hurrah, that did it. Thanks Mr. Freeman.
> Parentheses do not the tuple make. It's the comma. An expression
> surrounded by parentheses is just the expression, so you're trying to
> use each letter of your setting as a directory, I believe.
I assumed a single directory could be a case of a single element. Tuple
lesson duly noted.
> I take it you're not using the app directories loader?
Not yet.
- Stefan
At the risk of telling you something that you already know:
The app_directories_ loader should pull this stuff in for you, so long as
django.contrib.admin is in INSTALLED_APPS. Usually TEMPLATE_DIRS
is used to include a "templates" directory in your project root.