Найти - Пользователи
Полная версия: Путь к директории шаблонов.
Начало » Django » Путь к директории шаблонов.
1
I159
Имею стандартный проект, вида:
|-- activeapp
| |-- __init__.py
| |-- __init__.pyc
| |-- media
| | |-- css
| | | `-- style.css
| | |-- img
| | `-- js
| |-- models.py
| |-- models.pyc
| |-- tests.py
| `-- views.py
|-- activeblog.pidaproject
|-- __init__.py
|-- __init__.pyc
|-- manage.py
|-- settings.py
|-- settings.pyc
|-- templates
| |-- base.html
| `-- blogpost_list.html
|-- urls.py
`-- urls.pyc

6 directories, 17 files
i159@i159-desktop:~/djproj/activeblog$
В settings прописал путь:
def blank_path(*x):
return join(abspath(dirname(__file__)), *x)

TEMPLATE_DIRS = (
blank_path('templates')
В urls:
(r'^$', list_detail.object_list, {'queryset': BlogPost.objects.all(),}),
Стартовал сервер и получил ошибку, которой очень удивился:
Using loader django.template.loaders.filesystem.Loader:
/home/i159/djproj/activeblog/templates/activeapp/blogpost_list.html (File does not exist)
Откуда в пути берется activeapp?

Изменяю urls на:
(r'^$', direct_to_template, {'template': 'blogpost_list.html', }),
И шаблон отображается корректно.
Luam
Template name:

If template_name isn't specified, this view will use the template <app_label>/<model_name>_list.html by default.
Всё потому, что если тэмплейт не указан, то джанго строит вот тот путь что у тебя вышел <имя_приложения><имя_модели>
I159
Luam, спасибо.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB