ich eine Projektstruktur haben wie dieseVorlagen machen richtig auf Deployment-Server aber TemplateDoesNotExist Fehler auf runserver
mainproject
├── manage.py
├── mainproject
│ ├── settings.py
│ ├── templates
│ │ └── mainproject
│ │ └── index.html
│ ├── urls.py
│ ├── views.py
│ └── wsgi.py
└── app
├── admin.py
├── apps.py
├── forms.py
├── models.py
├── templates
│ └── app
│ ├── index.html
│ └── abc.html
├── urls.py
└── views.py
Jetzt in meinem settings.py habe ich
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['mainproject/templates', 'app/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',
],
},
},
]
Wenn ich diese verwenden, um auf Hauptdomain Auf meinem Deployment Server (bereitgestellt mit nginx und uwsgi) funktioniert das alles gut.
Ich bin in der Lage Mainproject-Index bei domain.com
und App-Index für den Zugriff auf domain.com/app
Aber wenn runserver
Verwendung nur domain.com:8000/app
Werke und domain.com:8000
geben Fehler TemplateDoesNotExist at /
.
Warum und wie könnte das behoben werden?
Template loader Obduktion:
Using engine django:
django.template.loaders.filesystem.Loader: /home/mohit/mainproject/templates/mainproject/index.html (Source does not exist)
django.template.loaders.filesystem.Loader: /home/mohit/app/templates/mainproject/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /home/mohit/Env/mainproject/lib/python2.7/site-packages/django/contrib/admin/templates/mainproject/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /home/mohit/Env/mainproject/lib/python2.7/site-packages/django/contrib/auth/templates/mainproject/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /home/mohit/mainproject/app/templates/mainproject/index.html (Source does not exist)
Wenn ich DIRS
Linie in TEMPLATES
in settings.py ändern und machen es
'DIRS': ['mainproject/mainproject/templates', 'app/templates'],
Dann funktioniert es auf runserver und funktioniert nicht auf Bereitstellungsserver.
Versuchen Sie relative Pfade in Ihren Einstellungen. http://www.morethanseven.net/2009/02/11/django-settings-tip-setting-relative-paths/ – xtranophilist
Ihre Vorlagenordnerpfade wären nicht gleich in Entwicklungs- und Produktionsservern, wie oben angemerkt ist es immer besser Verwenden Sie relative Pfade – Amar
Danke Jungs, das hat funktioniert. Wenn du das als Antwort posten kannst, werde ich es akzeptieren – MohitC