nijojob Posted March 10, 2017 Posted March 10, 2017 Hi, I have a html file in a templates folder but I can't load it in the project. This is the error:TemplateDoesNotExist at /MyApp2/dispatch.wsgi/index.htmlRequest Method: GETRequest URL: http://nijojob.heliohost.org/MyApp2/dispatch.wsgi/Django Version: 1.10.5Exception Type: TemplateDoesNotExistException Value: index.htmlException Location: /usr/local/python3.6/lib/python3.6/site-packages/django/template/loader.py in get_template, line 25Python Executable: Python Version: 3.6.0Python Path: ['/usr/local/python3.6/lib/python36.zip', '/usr/local/python3.6/lib/python3.6', '/usr/local/python3.6/lib/python3.6/lib-dynload', '/usr/local/python3.6/lib/python3.6/site-packages', '/home/nijojob/public_html/MyApp2']Server time: Thu, 9 Mar 2017 20:00:26 -0600Template-loader postmortemDjango tried loading these templates, in this order:Using engine django:django.template.loaders.filesystem.Loader: /templates/index.html (Source does not exist)django.template.loaders.app_directories.Loader: /usr/local/python3.6/lib/python3.6/site-packages/django/contrib/auth/templates/index.html (Source does not exist) And this is my view page:from django.http import HttpResponsefrom django.shortcuts import render def index(request): return render(request, 'index.html')
nijojob Posted March 10, 2017 Author Posted March 10, 2017 I don't have one in this. Tommy is running django 1.10. right? So, I have defined it as:# 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',# 'django.middleware.doc.XViewMiddleware', 'django.contrib.admindocs.middleware.XViewMiddleware',) ROOT_URLCONF = 'urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': ['templates'], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ # Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this # list if you haven't customized them: 'django.contrib.auth.context_processors.auth', 'django.template.context_processors.debug', 'django.template.context_processors.i18n', 'django.template.context_processors.media', 'django.template.context_processors.static', 'django.template.context_processors.tz', 'django.contrib.messages.context_processors.messages', ], }, },] INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites',)
Krydos Posted March 10, 2017 Posted March 10, 2017 Oh yeah, you're right on the new syntax https://docs.djangoproject.com/en/1.10/ref/templates/upgrading/#the-templates-settings I changed TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': ['templates'], 'APP_DIRS': True, ... to TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': ['/home/nijojob/public_html/MyApp2/templates'], 'APP_DIRS': True, ... and it seems to work now? You should probably use something like os.path.dirname to make it more portable if so.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now