1

According to the documentation, django should load templates automatically from my app if i have a folder named 'templates' in the root dir of the app.

I've added my app

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
)

I've created a templates folder

enter image description here

and i've setup urlpatterns to use the admin as the login page

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': '/'}),
)

i overwrote base_site.html but i can't see my customization, which i see if it add the folder to 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.
)

What am i doing wrong?

4

2 回答 2

0

问题是 django 在找到有效模板时可能会停止搜索,因此我的应用程序必须比 contrib 管理员排在第一位

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    # 'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'purchaseapp', #this is my app
    # 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',
)
于 2013-02-05T08:21:43.617 回答
0

您需要在 admin 下创建更多目录(来自docs):

为了覆盖其中的一个或多个,首先在项目的模板目录中创建一个管理目录。这可以是您在 TEMPLATE_DIRS 中指定的任何目录。

在此管理目录中,创建以您的应用命名的子目录。在这些应用程序子目录中创建以您的模型命名的子目录。请注意,管理应用程序在查找目录时会将模型名称小写,因此如果要在区分大小写的文件系统上运行应用程序,请确保以全小写命名目录。

要覆盖特定应用程序的管理模板,请从 django/contrib/admin/templates/admin 目录复制和编辑模板,并将其保存到您刚刚创建的目录之一。

于 2013-02-05T06:57:06.053 回答