本文介绍了django.模板在本地工作,但不在pythonanywhere.com上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在本地运行django时,我有一个正在运行的项目,但在pythonanywhere.com上运行时却没有.我收到错误TemplateDoesNotExist.
I have a working project in django when I run it local but not when I run it on pythonanywhere.com. I get error TemplateDoesNotExist.
我如何使其在pythonanywhere.com上运行?
How do I make it run on pythonanywhere.com?
我必须在代码中还是在pythonanywhere Web应用程序设置中做些什么?
Do i have to do something in the code or in pythonanywhere web app settings?
谢谢!
我的代码:settings.py
My code:settings.py
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEBUG = True
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'assets'),
)
推荐答案
您不应在 TEMPLATES
设置中使用相对目录'templates'
.尝试将 DIRS
更改为:
You shouldn't use the relative directory 'templates'
in your TEMPLATES
setting. Try changing DIRS
to:
'DIRS': [os.path.join(BASE_DIR, 'templates')],
这篇关于django.模板在本地工作,但不在pythonanywhere.com上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!