6👍
Since it works on other people’s machines, and since you have the app directories loader enabled, admin site enabled in INSTALLED_APPS
, and that’s all it should take for templates to be discovered (I mean, what more can one do?) – I can only assume something is wrong with your django installation.
This would be a good chance to start using virtualenvs and a fresh install of django to rule out your settings:
Fire up a terminal, navigate to your project directory (doesn’t actually matter…)
pip install virtualenv # if you don't have it.
virtualenv --no-site-packages env
# this creates a virtual python environment that doesn't include system packages
source env/bin/activate
# this forces your bash session to use that environment
pip install django
# installs a fresh copy of django to your new environment
cd path_to_my_django_project
# now go to your site directory
python manager.py runserver
# visit admin site.
31👍
I ran into the same problem, and I had to force pip to re-download django.
pip install -r requirements.txt --ignore-installed --force-reinstall --upgrade --no-cache-dir
Note: I know that the --no-cache-dir
option is necessary, I’m not certain that the other options are all required.
- [Django]-Django for loop counter break
- [Django]-How do I force Django to ignore any caches and reload data?
- [Django]-Asynchronous File Upload to Amazon S3 with Django
11👍
I am using Django Version 1.9.7 and when trying to add the admin_tools (menu and dashboard) to my application I had a similar issue. I found I had to do three things:
-
Edit the INSTALLED_APPS option in settings.py as follows (note that the admin_tools come before django contrib, ‘mines’ is the name of my application):
INSTALLED_APPS = [ 'admin_tools', 'admin_tools.theming', 'admin_tools.menu', 'admin_tools.dashboard', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'mines' ]
-
Edit the TEMPLATE setting in the settings.py file as follows (note the ‘loaders’ option that got added, and that APP_DIRS are now set to false):
TEMPLATES = [{ 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': False, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], 'loaders': [ 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', 'admin_tools.template_loaders.Loader', ], }, }]
-
And then finally I updated my urls.py file as follows (note the include for the admin_tools urls):
from django.conf.urls import include,url from django.contrib import admin from mines.views import SummaryByMapIcon urlpatterns = [ url(r'^admin_tools/', include('admin_tools.urls')), url(r'^admin/', admin.site.urls), url(r'^summarybymapicon$', SummaryByMapIcon, name='summarybymapicon'), ]
- [Django]-Navigation in django
- [Django]-How do I convert datetime.timedelta to minutes, hours in Python?
- [Django]-Django, ModelChoiceField() and initial value
11👍
I solved this same problem by reinstalling Django with the --no-cache-dir
option:
pip uninstall django
pip install django --no-cache-dir
Solved thanks to the answer here.
- [Django]-Get user information in django templates
- [Django]-Run Django shell in IPython
- [Django]-Accessing dictionary by key in Django template
9👍
In my case, I had to change APP_DIRS
from False
to True
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
- [Django]-Django pass object to include
- [Django]-Django 1.9 deprecation warnings app_label
- [Django]-Django dynamically filtering with q objects
2👍
Had the same issue. Strangely I found that sometime the template
and media
is not copied from your django/contrib/admin. Therefore you need to copy them to your virtual env django directory.
i.e from your /venv/lib/python2.7/site-packages/django/contrib
directory you need to
ln -s ~/Sites/your_dj_app/venv/django/contrib/admin/templates templates
and
ln -s ~/Sites/your_dj_app/venv/django/contrib/admin/media media
- [Django]-How to use pdb.set_trace() in a Django unittest?
- [Django]-Django cannot import name x
- [Django]-No module named pkg_resources
2👍
Inheriting a Django-application from an experienced magician, I wanted to understand the model by looking at it through Django-admin. As the app’s model was not in Admin yet, I created an admin.py
and ran into various problems. I tried All-Of-The-Above(TM) and found this:
-
I got the paths confused. I put the
admin.py
file into the wrong directory. If you have something like.../app/app/app/app/app...
make sure you know whichapp
needs to hold theadmin.py
. I figured that out by putting crap into the file and notice, that it would not crash. Hence ‘crap’ was not executed and something was wrong with the file. Fixed. -
TemplateDoesNotExist
on ‘admin/index.html’ The app’ssettings.py
was configured to only rundjango.template.backends.jinja2.Jinja2
as TEMPLATES BACKEND. But Admin needs the standarddjango.template.backends.django.DjangoTemplates
to make it work. I read, that it was possible to have two template-engines configured. I copied the standard-block from a different app. Fixed. -
TemplateDoesNotExist
on ‘admin/widgets/related_widget_wrapper.html’ While Admin was now working, looking at individual objects was still broken. I searched for the missing template and found it well in place. Changing anything on myTEMPLATES
setting would not improve anything. I manually inserted paths in'DIRS': []
, changed options, deleted the Jinja backend, nothing. It felt like was changing the wrong file again. Using the debugger, I found that even without configuring Jinja, it would still run Jinja. Finally, insettings.py
, I spotted this:FORM_RENDERER = 'django.forms.renderers.Jinja2'
and commenting it out got Admin going.
Not sure tho what it does with the rest of the application but for learning it’s okay.
- [Django]-Django South – table already exists
- [Django]-How to create table during Django tests with managed = False
- [Django]-Machine Learning (tensorflow / sklearn) in Django?
2👍
This issue may happen if you changed something in TEMPLATES
in settings.py:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates')
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},]
I have stumbled with this issue, alhamdulillah, my mistake was solved when I changed the 'APP_DIRS': False,
to 'APP_DIRS': True,
- [Django]-How can I allow django admin to set a field to NULL?
- [Django]-How do I get multiple values from checkboxes in Django
- [Django]-Django TemplateSyntaxError Could not parse the remainder: '()'
1👍
I meet the same error, after several times pip install and uninstall Django, it’s still not work. Then I download Django tar.gz file from Django website, and install from this file , all is fine. Hopefully this can help somebody.
- [Django]-How to log all sql queries in Django?
- [Django]-How to manually assign imagefield in Django
- [Django]-Cannot update a query once a slice has been taken
1👍
I ran into similar problem trying to configure django-admin-tools
for Django 2.0.2
Eventually I got it working. Here’s my TEMPLATES
settings.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': False,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'loaders' : [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'admin_tools.template_loaders.Loader',
]
},
},
]
This worked even as I overrode the default admin template.
Just be sure to take note of where to place the django-admin-tools
apps. See @Abrie Nel’s answer above.
- [Django]-Manually logging in a user without password
- [Django]-Usage of .to_representation() and .to_internal_value in django-rest-framework?
- [Django]-How do you limit list objects template side, rather than view side
1👍
for windows user the admin_tools in the templates section should be place in the begining
'loaders': [
**'admin_tools.template_loaders.Loader',**
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
- [Django]-Appending multiple querystring variables with curl
- [Django]-Django url pattern – string parameter
- [Django]-Django F expressions joined field
0👍
Despite their usefulness, the aforementioned answers are partial. I opine that the developer should know what is going on at the back-end, viz., “how” is this exception being raised.
As one can see in the exception that the Exception is TemplateDoesNotExist and the value name is the path, and something going wrong with the “loader.py” file. Although I was using Django 1.1.4, I am pretty sure the exception is being raised because of the line (in loader.py) where os.path.isdir(template_dir) is being checked. It cannot find the template folder(directory) in the django folder, which is located in the site-packages folder in the python’s Lib folder.
Intuitively one can say it is because of the inappropriate installation of django. It is, however, a good exercise to find out the cause of the exception by rummaging through the source. When this error occured in my project, I did not reinstall django, instead I copied the folders from root (C:/Python27/django/contrib) — yes I am using Windows — to its counterpart in site-packages and it worked!
- [Django]-ChoiceField in Django model
- [Django]-Django – signals. Simple examples to start
- [Django]-Django – How to do tuple unpacking in a template 'for' loop
0👍
I’m adding an “answer” as I cannot with my current “reputation” add a comment.
Following Aaron solution:
In a project with Django 1.4 with docker with the same issue (accessing yourproject/admin/login.html or yourproject/admin/index.html). I used in python.dockerfile this, and solved:
"RUN pip install -r requirements.txt --no-cache-dir"
Before I did this, I verified entering inside the docker, that inside the folder usr/local/lib/python2.7/site-packages/django/contrib/admin/ didnt exist the folder /templates/.
I was reading this before coming to this post:
https://www.mail-archive.com/search?l=django-users@googlegroups.com&q=subject:%22TemplateDoesNotExist+at+%5C%2Fadmin%5C%2F%22&o=newest&f=1
- [Django]-How to change empty_label for modelForm choice field?
- [Django]-Django: why i can't get the tracebacks (in case of error) when i run LiveServerTestCase tests?
- [Django]-How to pull a random record using Django's ORM?
0👍
For my case, I have INSTALLED_APPS good, but just need to point inside TEMPLATE_DIRS the django admin template:
import os #Put at the starting line
PROJECT_DIR = os.path.dirname(__file__)
TEMPLATE_DIRS = (
... #Another folder,
os.path.join(PROJECT_DIR, 'relative/path/to/virtualenv/my_env/django/contrib/admin/templates'),
)
And it works
- [Django]-How to aggregate (min/max etc.) over Django JSONField data?
- [Django]-Accessing request headers on django/python
- [Django]-How to unit test permissions in django-rest-framework?
-1👍
I think there are some packages that you didn’t install in INSTALLED_APPS, in my case I installed ‘import_export’ since I used ‘importexportmodels
- [Django]-Request.data in DRF vs request.body in Django
- [Django]-What is @permalink and get_absolute_url in Django?
- [Django]-ImportError: bad magic number in 'time': b'\x03\xf3\r\n' in Django
-2👍
I recommend you include ‘import_export’ in your ‘INSTALLED_APPS’ in settings.py. As explained from documentation, django-import-export is a Django application and library for importing and exporting data with included admin integration. Therefore for template of application to be render on the browser, the name of application must be included in settings.py. Unless other, you will get an error ‘Template does not exist’. Common sense, it is not possible to render the template of application, while the name of application is not not included in settings.py. So import_export is an application built in by Django, include it in settings.py.
- [Django]-Django custom managers – how do I return only objects created by the logged-in user?
- [Django]-No URL to redirect to. Either provide a url or define a get_absolute_url method on the Model
- [Django]-How to do "insert if not exist else update" with mongoengine?