Python django.template.loader可以';找不到模板
我正在向Web应用程序添加文本内容。 当我在本地服务器上运行应用程序时,我没有问题,但当我将模板上载到服务器时,它会返回以下错误:Python django.template.loader可以';找不到模板,python,django,templates,django-templates,Python,Django,Templates,Django Templates,我正在向Web应用程序添加文本内容。 当我在本地服务器上运行应用程序时,我没有问题,但当我将模板上载到服务器时,它会返回以下错误: Environment: Request Method: GET Request URL: http://www.centros-sbc.com/domiciliaciones Django Version: 1.5.1 Python Version: 2.7.3 Installed Applications: ('django.contrib.
Environment:
Request Method: GET
Request URL: http://www.centros-sbc.com/domiciliaciones
Django Version: 1.5.1
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'suit',
'django.contrib.admin',
'sbcweb',
'south',
'compressor',
'django.contrib.sitemaps',
'captcha')
Installed Middleware:
('django.middleware.cache.UpdateCacheMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware')
Template Loader Error:
Django tried loading these templates, in this order:
**Using loader django.template.loaders.filesystem.Loader: **
**/home/manager/webs/sbc-web/sbcweb/templates/general/domiciliaciones.html (File exists)**
Using loader django.template.loaders.app_directories.Loader:
/usr/local/lib/python2.7/dist-packages/django/contrib/auth/templates/general/domiciliaciones.html (File does not exist)
/usr/local/lib/python2.7/dist-packages/suit/templates/general/domiciliaciones.html (File does not exist)
/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/general/domiciliaciones.html (File does not exist)
**/home/manager/webs/sbc-web/sbcweb/templates/general/domiciliaciones.html (File exists)**
/usr/local/lib/python2.7/dist-packages/compressor/templates/general/domiciliaciones.html (File does not exist)
/usr/local/lib/python2.7/dist-packages/django/contrib/sitemaps/templates/general/domiciliaciones.html (File does not exist)
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "/home/manager/webs/sbc-web/sbcweb/views/general.py" in domiciliaciones
27. return render_to_response('general/domiciliaciones.html', response, context_instance=RequestContext(request))
File "/usr/local/lib/python2.7/dist-packages/django/shortcuts/__init__.py" in render_to_response
29. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py" in render_to_string
170. t = get_template(template_name)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py" in get_template
146. template, origin = find_template(template_name)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py" in find_template
139. raise TemplateDoesNotExist(name)
Exception Type: TemplateDoesNotExist at /domiciliaciones
Exception Value: general/domiciliaciones.html
以下是我的模板加载程序:
TEMPLATE_LOADERS = (
#'django_mobile.loader.Loader',
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
#'django.template.loaders.eggs.Loader',
)
我的模板目录:
TEMPLATE_DIRS = (
os.path.join(APP_PATH, "templates"),
)
应用程序路径:
APP_PATH = os.path.dirname(os.path.abspath(__file__))
事情是这样的。
我只是对/domiciliaciones.html的文本做了一些修改,处理了.po翻译文件并覆盖了翻译文件和.html
我试图修复页面,使其恢复到原来的状态(没有修改),但也没有效果。
如果有人能帮上忙,那就太好了,我有点急着去解决这个问题。
我不知道你是否需要更多关于应用程序的信息,请告诉我
非常感谢 也许我能回答你的问题!在Django 1.8.2中,自1.8版以来,已弃用:改为设置Django模板后端的DIRS选项。,因此,您不应该设置模板DIRS,在我看来,您应该设置
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'APP_DIRS': True,
}
]
我花了半天时间在我的WebApp中解决这个问题!我想这对你有帮助 多谢各位。我正在使用Django 1.8.2,我正好遇到了这个问题。像oyu一样挠了我几个小时的头。