By ebizbytes
Installed Django 1.8.4, Python 2.7.9 and SwampDragon 0.4.2.2; executed " ./manage.py runserver 0.0.0.0:8000" and selected http://<mysite>:8000 in Opera browser. Django debug enabled.
Request Method: GET
Request URL: http://<mysite>:8000/
Django Version: 1.8.4
Exception Type: TemplateDoesNotExist
Exception Value:
index.html
Exception Location: /usr/local/lib/python2.7/dist-packages/django/template/loader.py in select_template, line 76
Python Executable: /usr/bin/python
Python Version: 2.7.9
Python Path:
['/home/admin/www/swampdragon.net',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages']
Template-loader postmortem
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/index.html (File does not exist)
/usr/local/lib/python2.7/dist-packages/django/contrib/auth/templates/index.html (File does not exist)
Which is correct - those files do not exist! There are several files in /usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/admin however, including index.html:
total 112
-rw-r--r-- 1 root staff 1140 Sep 15 21:00 search_form.html
-rw-r--r-- 1 root staff 790 Sep 15 21:00 submit_line.html
-rw-r--r-- 1 root staff 1469 Sep 15 21:00 related_widget_wrapper.html
-rw-r--r-- 1 root staff 1012 Sep 15 21:00 prepopulated_fields_js.html
-rw-r--r-- 1 root staff 491 Sep 15 21:00 popup_response.html
-rw-r--r-- 1 root staff 561 Sep 15 21:00 pagination.html
-rw-r--r-- 1 root staff 1440 Sep 15 21:00 object_history.html
-rw-r--r-- 1 root staff 1695 Sep 15 21:00 login.html
-rw-r--r-- 1 root staff 437 Sep 15 21:00 invalid_setup.html
-rw-r--r-- 1 root staff 2989 Sep 15 21:00 index.html
-rw-r--r-- 1 root staff 301 Sep 15 21:00 filter.html
-rw-r--r-- 1 root staff 2209 Sep 15 21:00 delete_selected_confirmation.html
-rw-r--r-- 1 root staff 2301 Sep 15 21:00 delete_confirmation.html
-rw-r--r-- 1 root staff 372 Sep 15 21:00 date_hierarchy.html
-rw-r--r-- 1 root staff 1559 Sep 15 21:00 change_list_results.html
-rw-r--r-- 1 root staff 3512 Sep 15 21:00 change_list.html
-rw-r--r-- 1 root staff 3697 Sep 15 21:00 change_form.html
-rw-r--r-- 1 root staff 316 Sep 15 21:00 base_site.html
-rw-r--r-- 1 root staff 3667 Sep 15 21:00 base.html
-rw-r--r-- 1 root staff 385 Sep 15 21:00 app_index.html
-rw-r--r-- 1 root staff 1095 Sep 15 21:00 actions.html
-rw-r--r-- 1 root staff 527 Sep 15 21:00 500.html
-rw-r--r-- 1 root staff 268 Sep 15 21:00 404.html
drwxr-sr-x 4 root staff 4096 Sep 15 21:00 ../
drwxr-sr-x 2 root staff 4096 Sep 15 21:00 includes/
drwxr-sr-x 2 root staff 4096 Sep 15 21:00 edit_inline/
drwxr-sr-x 3 root staff 4096 Sep 15 21:00 auth/
drwxr-sr-x 5 root staff 4096 Sep 15 21:00 ./
Given that this is essentially an “out-of-the-box” installation - particularly where the ‘admin’ files are concerned - is this a Django bug?
I have Googled for the “TemplateDoesNotExist at /” error message but although others have encountered similar problems, there does not seem to be a definitive solution. Which is surprising, as this appears to be a fundamental issue.
Perhaps I will simply disable the Django admin facility for the time being.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Oops! This was due to the inclusion of the following line in the urls.py file:
url(r'^$', TemplateView.as_view(template_name='index.html'), name='home'),
I had derived that from the tutorial at http://swampdragon.net/tutorial/part-2-swampdragon-tutorial.
I’ve no idea why that didn’t work but if I omit the line I get the basic “Welcome to Django” web service running.
Heya,
While the reason behind the error has been posted, let’s do a deepdive in case anyone else gets this and needs more info on the matter:
The error you’re seeing, TemplateDoesNotExist, is a common error in Django when it can’t find the template it’s instructed to render.
Let’s address the main points:
Django’s Admin Site: The error message suggests that Django is looking for index.html in the paths:
/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/index.html/usr/local/lib/python2.7/dist-packages/django/contrib/auth/templates/index.htmlHowever, Django’s admin site templates reside under /usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/admin/ by default, so index.html should actually be located at /usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/admin/index.html.
URL Configuration: When you go to http://<mysite>:8000/, Django uses your root URL configuration to determine which view should handle this request. Make sure you’ve set up the admin site URLs correctly. Typically, it looks like:
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]
This means that the admin site should be accessed via http://<mysite>:8000/admin/ and not the root URL.
Out-of-the-Box: Django’s admin site should work out-of-the-box when properly configured. If you’ve followed standard installation steps, it’s unlikely to be a Django bug, especially for such a fundamental feature.
Django and Python Versions: Django 1.8.4 and Python 2.7.9 are both outdated. Django 1.8’s end-of-life was in April 2018, and Python 2.7’s end-of-life was in January 2020. It is highly recommended to upgrade to more recent versions, especially for production systems, due to performance, security, and feature updates.
Suggested Actions:
urls.py and that you’re accessing it from the right URL.'django.contrib.admin' to your INSTALLED_APPS.http://<mysite>:8000/admin/ directly to access the Django admin site.Remember, Django’s error messages and stack traces are very informative. Follow the paths and messages provided, and they’ll often lead you directly to the source of the problem.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.