Django TemplateDoesNotExist admin/login.html

回眸只為那壹抹淺笑 提交于 2019-12-04 05:06:42

问题


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 not work... Please Help!


回答1:


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')]



回答2:


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.




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/32575043/django-templatedoesnotexist-admin-login-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!