按照documentation,Django的應該自動從我的應用程序,如果我有一個在應用程序的根目錄,命名爲「模板」文件夾中加載模板。的Django模板自動加載工作不適合我的應用程序
我已經添加了我的應用程序
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
# 'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
# Use email as username https://github.com/dabapps/django-email-as-username
'emailusernames',
'purchaseapp' # this is my app
)
我創建了一個模板文件夾
,我已經設置URL模式使用admin作爲登錄頁面
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'timely.views.home', name='home'),
# url(r'^timely/', include('timely.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
url(r'^$', hello),
url(r'^accounts/logout/$', 'django.contrib.auth.views.logout'),
url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'admin/login.html'}),
url(r'^accounts/$', 'django.views.generic.simple.redirect_to', {'url': '/'}),
url(r'^accounts/profile/$', 'django.views.generic.simple.redirect_to', {'url': '/'}),
)
我改寫base_site.html,但我不能看到我的定製,WH ich我看它是否將文件夾添加到TEMPLATE_DIRS
TEMPLATE_DIRS = (
"/Users/nicola/Documents/Aptana Studio 3 Workspace/timely/purchaseapp/templates",
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
我在做什麼錯了?
順便說一句,也許你會希望添加django.template.loaders .app_directories.Loader添加到您的模板加載器,以便從應用中加載模板,而無需在TEMPLATE_DIRS中選擇每個模板。 – simplylizz
我遇到過類似的問題,將模板文件夾添加到項目的根目錄並在應用程序文件夾中解決了我的問題。 – vedarthk
@simplylizz不,我已經擁有了,感謝您的建議 –