Jump to content

Django Template Not Loading On Tommy


Recommended Posts

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.html

Request Method: GET

Request URL: http://nijojob.heliohost.org/MyApp2/dispatch.wsgi/

Django Version: 1.10.5

Exception Type: TemplateDoesNotExist

Exception Value:

index.html

Exception Location: /usr/local/python3.6/lib/python3.6/site-packages/django/template/loader.py in get_template, line 25

Python Executable:

Python Version: 3.6.0

Python 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 -0600

Template-loader postmortem

Django 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 HttpResponse

from django.shortcuts import render

 

def index(request):

return render(request, 'index.html')

Link to comment
Share on other sites

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',

)

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...