Stuck with TemplateDoesNotExist at /

246 views
Skip to first unread message

vogernewsletters

unread,
Sep 2, 2013, 8:50:58 AM9/2/13
to django...@googlegroups.com
Hi I am new to both Python and Django. I am studying various tutorials and now I am following the tutorial from http://gettingstartedwithdjango.com where the author walks through the creation of a simple microblog.

I tried to follow the tutorial to the point but I keep getting TemplateDoesNotExist at /. Then I tried to modify few things but still I keep getting the error. Right now the configuration is like this.

My project tree:
microblog/
├── manage.py
├── microblog
│οΏ½οΏ½ ├── __init__.py
│οΏ½οΏ½ ├── __init__.pyc
│οΏ½οΏ½ ├── settings
│οΏ½οΏ½ │οΏ½οΏ½ ├── base.py
│οΏ½οΏ½ │οΏ½οΏ½ ├── base.pyc
│οΏ½οΏ½ │οΏ½οΏ½ ├── __init__.py
│οΏ½οΏ½ │οΏ½οΏ½ ├── __init__.pyc
│οΏ½οΏ½ │οΏ½οΏ½ ├── local.py
│οΏ½οΏ½ │οΏ½οΏ½ └── local.pyc
│οΏ½οΏ½ ├── urls.py
│οΏ½οΏ½ ├── urls.pyc
│οΏ½οΏ½ ├── views.py
│οΏ½οΏ½ ├── wsgi.py
│οΏ½οΏ½ └── wsgi.pyc
├── requirements.txt
└── templates
οΏ½οΏ½οΏ½ ├── 500.html
οΏ½οΏ½οΏ½ └── index.html

My settings/base.py which is essentially equivalent to settings.py
import os
...
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
...
TEMPLATE_LOADERS = (
οΏ½οΏ½οΏ½ 'django.template.loaders.filesystem.Loader',
οΏ½οΏ½οΏ½ 'django.template.loaders.app_directories.Loader',
οΏ½οΏ½οΏ½ 'django.template.loaders.eggs.Loader',
)
...
TEMPLATE_DIRS = (
οΏ½οΏ½οΏ½ os.path.join(PROJECT_ROOT, 'templates'),
)

My urls.py

from django.views.generic import TemplateView
...
urlpatterns = patterns('',
...
οΏ½οΏ½οΏ½ url(r'^$', TemplateView.as_view(template_name="index.html")),
...
)

and I added a views.py just in case
from django.views.generic import TemplateView

class HomepageView(TemplateView):
οΏ½οΏ½οΏ½ template_name = "index.html"

Always I get the error message "TemplateDoesNotExist at /"

Django tried loading these templates, in this order:

  • Using loaderοΏ½django.template.loaders.filesystem.Loader:
    • /home/voger/PycharmProjects/microblog/microblog/templates/index.htmlοΏ½(File does not exist)
  • Using loaderοΏ½django.template.loaders.app_directories.Loader:
    • /home/voger/blog-venv/lib/python2.7/site-packages/django/contrib/auth/templates/index.htmlοΏ½(File does not exist)
    • /home/voger/blog-venv/lib/python2.7/site-packages/django/contrib/admin/templates/index.htmlοΏ½(File does not exist)
  • Using loaderοΏ½django.template.loaders.eggs.Loader:

If it would try the first two lines the file is sitting right there so what is wrong with it?


Sandro Dutra

unread,
Sep 2, 2013, 9:07:37 AM9/2/13
to django...@googlegroups.com
Django cannot load the template, probably the path is wrong, try to put this in your settings:

TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), '..', 'templates').replace('\\','/'),)

About the views, I think you don't need to code it if in your urls.py you already used the TemplateView.as_view


2013/9/2 vogernewsletters <vogernew...@yahoo.gr>
Hi I am new to both Python and Django. I am studying various tutorials and now I am following the tutorial from http://gettingstartedwithdjango.com where the author walks through the creation of a simple microblog.

I tried to follow the tutorial to the point but I keep getting TemplateDoesNotExist at /. Then I tried to modify few things but still I keep getting the error. Right now the configuration is like this.

My project tree:

microblog/
├── manage.py
├── microblog
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── settings
│   │   ├── base.py
│   │   ├── base.pyc
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── local.py
│   │   └── local.pyc
│   ├── urls.py
│   ├── urls.pyc
│   ├── views.py
│   ├── wsgi.py
│   └── wsgi.pyc
├── requirements.txt
└── templates
    ├── 500.html
    └── index.html

My settings/base.py which is essentially equivalent to settings.py
import os
...

PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
...
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',

    'django.template.loaders.eggs.Loader',
)
...
TEMPLATE_DIRS = (
    os.path.join(PROJECT_ROOT, 'templates'),
)

My urls.py

from django.views.generic import TemplateView
...
urlpatterns = patterns('',

...

    url(r'^$', TemplateView.as_view(template_name="index.html")),
...
)

and I added a views.py just in case
from django.views.generic import TemplateView

class HomepageView(TemplateView):
    template_name = "index.html"

Always I get the error message "TemplateDoesNotExist at /"


Django tried loading these templates, in this order:

  • Using loader django.template.loaders.filesystem.Loader:
    • /home/voger/PycharmProjects/microblog/microblog/templates/index.html (File does not exist)
  • Using loader django.template.loaders.app_directories.Loader:
    • /home/voger/blog-venv/lib/python2.7/site-packages/django/contrib/auth/templates/index.html (File does not exist)
    • /home/voger/blog-venv/lib/python2.7/site-packages/django/contrib/admin/templates/index.html (File does not exist)
  • Using loader django.template.loaders.eggs.Loader:

If it would try the first two lines the file is sitting right there so what is wrong with it?


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

vogernewsletters

unread,
Sep 2, 2013, 9:25:58 AM9/2/13
to django...@googlegroups.com
Well, this is embarrassing but the file wasn't in the path after all. A simple ls would reveal that. It was one level higher than that.
So I moved the directory templates inside the microblog and now it works.
Reply all
Reply to author
Forward
0 new messages