TemplateDoesNotExist login.html django1.4 [duplicate] - django

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!

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

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

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.

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

Add your app name in INSTALLED_APPS list inside settings.py.

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.

Related

Disable Django admin

I'm in a selection process and I must develop a software in Django with the restriction of not being able to use the admin included in the framework.
I tried removing it from the INSTALLED_APPS. But when I run a migration I get the error:
'No installed app with label 'admin'
Is there any other configuration that I should do or what is the correct way to do it?
Be sure to remove it from:
urls.py
remove from urlpatterns
remove the import statement
INSTALLED_APPS
That's it.

Django TemplateDoesNotExist admin/login.html

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!
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')]
Django by default looks for templates in each app having directory name "templates".
you can add your own path in settings.py file
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.
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."
Add your app name in INSTALLED_APPS list inside settings.py.
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.

Django and admin templates

I have created a Django project and packaged it using py2exe. It also uses cherrypy as a webserver for the project to get served. I would like to ask a question. My executable django app can't find the admin templates. So i was wondering how does Django locate the admin templates? Do i need to copy them from django/contrib/admin/templates to my templates folder?
The error i get when i execute (using the derived exe) my programm is
TemplateDoesNotExist
Exception Value:admin/login.html django
that is when i visit the admin backend of my project. If i run it normaly through manage.py
admin works fine.
The admin templates are located in django\contrib\admin\templates - you'll have to include them or copy them as is to a template folder in your main app.
An other option would be to put them in a seperate dierctory and add this directory to TEMPLATE_DIRS in your settings.py. This might be a good option for you because it keeps the original files separated from your project templates.

django-cms + grappelli

If anyone knows how to make django-cms play with grappelli, please give some tips
Well I've just gone through a fairly epic adventure, the story of which might be of some use to you. The end point of said adventure was getting django-cms 2.1.3 working with django-filebrowser-no-grappelli . Whilst that may sound in fact like the opposite of what you want, I ended up there because what I really wanted was to get django-cms working with filebrowser. Without grappelli though the standard django-filebrowser does not work as expected. But with grappelli django-cms does not work as expected. So therein lay the rub, to quote shakespeare. Getting django-cms working with filebrowser was relatively straight forward except for the fact that when trying to upload files with uploadify (which is shipped with filebrowser), after selecting the files in the file dialog, nothing happened. Eventually I figured out that this was because the jquery library was being loaded twice: once by filebrowser for use with uploadify, and once by django-cms. So by commenting out the second line in this file:
your site packages dir/cms/templates/cms/toolbar/toolbar.html
which loads jquery.min.js, uploadify worked as expected. Soooo...if you just want to get django-cms working with grappelli so you can use filebrowser, the above might be helpful. Here is my settings file for reference.
My solution is to implement 2 subdomains, 'www' and 'cms', in each of which a separate instance of the Django site is running with a different STATIC_ROOT and a modified INSTALLED_APPS. grappelli runs in the 'www' subdomain. It is not running in the 'cms' subdomain, so that you can use django-cms there.
Set up a subdomain: cms.example.com
Modify your webserver to serve this subdomain. Use the same settings as your main django site but point to a different script handler. e.g. if using wsgi direct the server to run wsgi_cms.py
cp wsgi.py wsgi_cms.py. Edit wsgi_cms.py and change the line
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
to os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings_cms")
settings_cms.py :
:
from settings import *
INSTALLED_APPS.remove('grappelli.dashboard')
INSTALLED_APPS.remove('grappelli')
STATIC_ROOT = os.path.join('/what/ever/static_cms/')
STATIC_URL = '/static_cms/'
ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/`
modify settings.py: change INSTALLED_APPS from a tuple to a list
restart web servers
./manage.py collectstatic --settings=myproject.settings_cms
your regular site continues as normal. To edit django-cms pages with grappelli disabled go to http://cms.example.com/admin/cms/page/
I've once made a django-cms fork on github that supports grappelli, it's a bit outdated, but maybe helps you to get started or probaly you'd like to contribute.

Django syncdb can't find my apps

I'm a django newbie and have been having a problem.
In my project root I created a folder called 'local_apps' and within it I put the app 'myapp'. I updated the INSTALLED_APPS within settings.py with: myproject.local_apps.myapp
However when I try to syncbd, Django gives an error: 'no module named local_apps.myapp exists'
When I put 'myapp' back in the project root, it works again but I dont want it that way. I want to keep my apps in the folder 'local_apps'.
Can you tell me what I am doing wrong here.
Thanks in advance.
I think that's a generic python error, not a Django error.
Maybe you need to create an __init__.py file in the local_apps directory, so python knows it's a module.
Do you have a models.py within the myapp folder? I think Django may need to see that file in the app.
[Edit: actually, I think wisty above may be right, make sure you have an __init__.py, if you do, try the models.py.]
I was facing the error: ImportError: No module named foo
To solve this, I just added the Django site package to the Python path at settings.py module like this:
PKG_DIR = os.path.dirname(__file__)
sys.path.append(PKG_DIR)