【发布时间】:2011-09-23 02:07:10
【问题描述】:
我正在尝试让 Django 管理界面显示我的数据库中的对象,但是每当我单击模型的名称时,都会遇到错误:
TemplateDoesNotExist 在/myAppName/myModelName/
我不明白:为什么我首先需要管理界面的任何模板?
我认为管理界面已经为我们预先制作好了,我们不需要任何自定义 HTML...对吗?
settings.py:
ADMIN_MEDIA_PREFIX = '/admin_media/'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.contenttypes',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
'my_app_name',
)
TEMPLATE_DIRS = (
'<project_path>/templates',
'<django_path>/v1_2/contrib/admin/templates',
)
admin.py:
from my_app.models import MyModel
from django.contrib import admin
admin.site.register(MyModel)
models.py:
from django.db import models
class MyModel(models.Model):
#my fields here
【问题讨论】:
-
您的模型和管理员定义看起来如何?
-
@DontCare4Free:它们看起来像上面那样。
-
是否有异常消息?您是否有机会使用自定义字段?此外,管理模板不应在您的 TEMPLATE_DIRS 中,因为它们会自动包含在管理应用程序中。
-
大概是管理员使用模板加载器来加载模板,你在设置中改变了吗?
标签: python django django-admin django-templates