我在运行Python 2.4的服务器上有一个django(v1.1.1)。在我的localhost / development计算机上,该网站运行良好。当我将文件上传到生产服务器时,它似乎工作正常,但在页面刷新后我收到随机的TemplateDoesNotExist错误。
在跟踪报告中,我查看了TEMPLATE_DIRS变量以确保我指向正确的位置,并且每次刷新页面时它实际上都会更改:
TEMPLATE_DIRS
('templates','/ var / www / vhosts / mysit.com / apps')
和这个
TEMPLATE_DIRS
('templates','/ var / www / django-sites / apps / templates')
当我刷新页面时,django / python如何在两个不同的位置查看?经过3-4次尝试后,它会突然运行,直到我刷新或转到下一页。正确的位置是/var/www/vhosts/mysite.com/apps/templates,它在我的settings.py文件中定义:
# 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',
)
我很感激帮助!
答案 0 :(得分:0)
这听起来像是您的apache配置问题或者您用于Web服务器的问题。 PROJECT_ROOT:
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
取决于当前运行应用程序的环境所设置的绝对路径。确保Web服务器配置中只存在一个用于处理URL的路由。
其次,确保所有django环境都已彻底关闭,您可能会有一些旧的,配置错误的环境来处理请求。