首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >django中零星的TemplateDoesNotExist错误

django中零星的TemplateDoesNotExist错误
EN

Stack Overflow用户
提问于 2010-06-25 02:51:18
回答 1查看 575关注 0票数 1

我在运行Python2.4的服务器上安装了django (v1.1.1)。在我的本地主机/开发计算机上,这个站点运行得很好。当我将文件上传到生产服务器时,它似乎工作得很好,但在页面刷新之后,我收到随机的TemplateDoesNotExist错误。

在跟踪报告中,我查看了TEMPLATE_DIRS变量,以确保我指向了正确的位置,并且每次刷新页面时,它实际上都会发生变化:

TEMPLATE_DIRS

(‘template’,'/var/www/vhosts/mysite.com/apps')

还有这个

TEMPLATE_DIRS

(‘template’,‘/var/www/django-site/apps/template’)

当我刷新页面时,django/python怎么可能在两个不同的位置查找?3-4次尝试后,它突然开始工作,直到我刷新或转到下一页。正确的位置是/var/www/vhosts/mysite.com/apps/templates,这是在我的settings.py文件中定义的:

代码语言:javascript
复制
# Django settings for django-sites project.

DEBUG = False
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Your Name', 'your_email@domain.com'),
)

MANAGERS = ADMINS

DATABASE_ENGINE = 'mysql'
DATABASE_NAME = 'mysite'
DATABASE_USER = 'mysuser'
DATABASE_PASSWORD = 'mypass'
DATABASE_HOST = 'www.mysite.com'            
DATABASE_PORT = ''  


# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = ''

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = ''

# URL prefix for admin media -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
ADMIN_MEDIA_PREFIX = '/admin_media/'

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'mysecretkey'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.load_template_source',
    'django.template.loaders.app_directories.load_template_source',
#     'django.template.loaders.eggs.load_template_source',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
)

ROOT_URLCONF = 'apps.urls'
URL_ROOT_LEAD_CAPTURE = '/lead-capture/'

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.request',
    'django.core.context_processors.auth',
)

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

TEMPLATE_DIRS = (
    os.path.join(PROJECT_ROOT, 'templates'),
    '/var/www/vhosts/mysite.com/apps/templates',
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.admin',
    'django.contrib.admindocs',
)

非常感谢你的帮助!

EN

回答 1

Stack Overflow用户

发布于 2011-08-07 01:51:58

这听起来像是您的apache配置或您正在为web服务器使用的任何东西的问题。PROJECT_ROOT:

代码语言:javascript
复制
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

依赖于当前的绝对路径,这是由运行应用程序的环境设置的。确保您的web服务器配置中只存在一个用于处理URL的路由。

其次,确保所有django环境都被彻底关闭,您可能会有一些旧的、错误配置的环境来处理请求。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3113015

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档