2
votes

I'm trying to get the Django admin interface to display objects from my database, but whenever I click the name of a model, I come across an error:

TemplateDoesNotExist at /myAppName/myModelName/

I don't understand: Why do I need any templates for the admin interface in the first place?
I thought the admin interface was already pre-made for us, and that we didn't need any custom HTML for it... right?


settings.py:

ADMIN_MEDIA_PREFIX = '/admin_media/'

INSTALLED_APPS = (
  'django.contrib.auth',
  'django.contrib.sessions',
  'django.contrib.sites',
  'django.contrib.messages',

  'django.contrib.contenttypes',
  # Uncomment the next line to enable the admin:
  'django.contrib.admin',
  # Uncomment the next line to enable admin documentation:
  'django.contrib.admindocs',

  'my_app_name',
)

TEMPLATE_DIRS = (
  '<project_path>/templates',
  '<django_path>/v1_2/contrib/admin/templates',
)

admin.py:

from my_app.models import MyModel
from django.contrib import admin
admin.site.register(MyModel)

models.py:

from django.db import models
class MyModel(models.Model):
    #my fields here
1
How do your model and admin definitions look? - Teo Klestrup Röijezon
@DontCare4Free: They look like the above. - user541686
is there any message for the exception? Are you by any chance using custom fields? Also, the admin templates shouldn't be in your TEMPLATE_DIRS, since they are automatically included by the admin app. - Teo Klestrup Röijezon
Presumably admin uses template loaders to load templates, did you change them in your settings? - shanyu

1 Answers

1
votes

OMG, this is so tricky! I just ran into the solution by pure chance:

The problem was that I was going into the admin interface with a URL of the form:

127.0.0.1:8000/admin

while in fact I should have said:

127.0.0.1:8000/admin/

that solved the issue. (!)