django.template.loader无法找到模板

时间:2014-10-03 09:10:44

标签: python django templates django-templates

我正在向webapp添加文本内容。 当我在本地服务器上运行应用程序时,我没有任何问题,但是当我将模板上传到服务器时,它返回给我这个错误:

    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

我试图修复返回原始页面的页面(没有我的更改),但它既不起作用也不起作用。 如果有人可以帮助它会很棒,我有点想要解决这个问题。 我不知道您是否需要有关该应用的更多信息,请告诉我们!

非常感谢提前!

1 个答案:

答案 0 :(得分:1)

也许我可以回答你的问题!在Django 1.8.2中,从版本1.8开始不推荐:改为设置DjangoTemplates后端的DIRS选项。,所以,你不应该设置 TEMPLATE_DIRS ,在我的意见中,你应该设置

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['templates'],
        'APP_DIRS': True,
       }
]   

我花了半天时间在我的WebApp中解决这个问题!我想这会对你有所帮助!