问题
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.
How do I make it run on pythonanywhere.com?
Do i have to do something in the code or in pythonanywhere web app settings?
Thanks!
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'),
)
回答1:
You shouldn't use the relative directory 'templates'
in your TEMPLATES
setting. Try changing DIRS
to:
'DIRS': [os.path.join(BASE_DIR, 'templates')],
来源:https://stackoverflow.com/questions/45217545/django-templates-working-local-but-not-on-pythonanywhere-com