Django TemplateDoesNotExist admin/login.html

后端 未结 5 627
独厮守ぢ
独厮守ぢ 2021-01-21 19:04

I am working with django 1.4. And this error appeared:

TemplateDoesNotExist at /admin/ admin/login.html

I tried to reinstall django, but i did

相关标签:
5条回答
  • 2021-01-21 19:27

    Assuming that you are trying to use the default Django admin, be sure that 'django.contrib.admin' is in the INSTALLED_APPS section of your settings.py file.

    0 讨论(0)
  • 2021-01-21 19:38

    If you're getting a "TemplateDoesNotExist" error, that means you are referring to a template that does not exist. :) You should have a templates directory, and check to see if admin/login.html exists in that directory path.

    This is the Django 1.4 template documentation. IMO the Django documentation is quite good compared to most stock documentation.

    Also you should know that the admin interface is not really designed to be customized. The built-in admin interface has a login feature already built-in, if you create a superuser with the manage.py script. If you're trying to build your own template, you should do so separate from the admin interface, unless you disable/remove the built-in admin interface completely and design your own from scratch. Modifying built-in admin code is more trouble than it's worth in my opinion.

    0 讨论(0)
  • 2021-01-21 19:45

    I got that same error trying to use the default built-in login functionality.

    My settings.py has the default settings, 'django.contrib.admin' is in the INSTALLED_APPS section of my settings.py file, as suggested by sean.

    Elaborating on Tim's answer, I believe that we are refering to a missing template.

    See the docs at https://docs.djangoproject.com/en/1.7/topics/auth/default/#django.contrib.auth.views.login: "It’s your responsibility to provide the html for the login template, called registration/login.html by default."

    0 讨论(0)
  • 2021-01-21 19:47

    You can try to add the admin tempates path name to TEMPLATES['DIRS'] in your django settings.py

    The default TEMPLATES:

    'DIRS': [os.path.join(BASE_DIR, 'templates')]
    

    change to if you are using Django project created by Pycharm:

    'DIRS': [os.path.join(BASE_DIR, 'templates'),
             os.path.join(BASE_DIR, 'venv/lib/site-packages/django/contrib/admin/templates')]
    
    0 讨论(0)
  • 2021-01-21 19:50

    Django by default looks for templates in each app having directory name "templates". you can add your own path in settings.py file

    0 讨论(0)
提交回复
热议问题