I have a problem described in this post I have no idea what is the reason of the problem so I decided to create a new project both in Docker like without it. In both cases I get the same problem. To wit to newly created project I add only to urls.py:
from rest_framework.documentation import include_docs_urls
API_TITLE = 'API title'
API_DESCRIPTION = '...'
urlpatterns = [
url(r'^docs/', include_docs_urls(title=API_TITLE, description=API_DESCRIPTION))
]
and in Docker requirements.txt I add coreapi. In case of project without Docker I install via virtualenv pip3 install coreapi. That is all what in my opinion I should do in order to get a view like at the top of this site from documentation Obviously at http://localhost:8000/docs/ However in both cases I get
TemplateDoesNotExist at /docs/
rest_framework/docs/index.html
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.app_directories.Loader: /usr/local/lib/python3.6/site-packages/django/contrib/admin/templates/rest_framework/docs/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /usr/local/lib/python3.6/site-packages/django/contrib/auth/templates/rest_framework/docs/index.html (Source does not exist)
(in virtualenv there is only different path)
Does anyone have an idea what might be wrong? If more details will be needed I will add it immediately to this post, just let me know.
UPDATE
When I add rest_framowork to INSTALLED_APPS I get:
AttributeError at /docs/
'NoneType' object has no attribute 'items'
Request Method: GET
Request URL: http://localhost:8001/docs/
Django Version: 1.11
Exception Type: AttributeError
Exception Value:
'NoneType' object has no attribute 'items'
Exception Location: /usr/local/lib/python3.6/site-packages/rest_framework/templatetags/rest_framework.py in items, line 244
Python Executable: /usr/local/bin/python3
Python Version: 3.6.1
Python Path:
['/code',
'/usr/local/lib/python36.zip',
'/usr/local/lib/python3.6',
'/usr/local/lib/python3.6/lib-dynload',
'/usr/local/lib/python3.6/site-packages']
In template /Users/myUser/Projects/DjangoTest/lib/python3.6/site-packages/rest_framework/templates/rest_framework/docs/sidebar.html, error at line 8
UPDATE2
I have in my app on heroku rest_framowork at the top of INSTALLED_APPS however http://myapp.herokuapp.com/docs/ returns:
AttributeError at /docs/
'NoneType' object has no attribute 'items'
Request Method: GET
Request URL: http://myapp.herokuapp.com/docs/
Django Version: 1.11
Exception Type: AttributeError
Exception Value:
'NoneType' object has no attribute 'items'
Exception Location: /app/.heroku/python/lib/python3.6/site-packages/rest_framework/templatetags/rest_framework.py in items, line 244
Python Executable: /app/.heroku/python/bin/python
Python Version: 3.6.1
Python Path:
['/app/Project/backend/project',
'/app/.heroku/python/bin',
'/app',
'/app/.heroku/python/lib/python36.zip',
'/app/.heroku/python/lib/python3.6',
'/app/.heroku/python/lib/python3.6/lib-dynload',
'/app/.heroku/python/lib/python3.6/site-packages']
Server time: Mon, 17 Jul 2017 12:49:49 +0000
SOLTUION
I used djangorestframework==3.6.2 instead of djangorestframework==3.6.3 in requirements.txt. I have no idea why version 3.6.3 doesn't work.
This likely means that you didn't add rest_framework to the INSTALLED_APPS in the settings.py file.
Related
I'm using manage.py runserver on a MacOs Catalina OS as development. I have some templates that fit my built-in class based views. For example:
CuadroDeControl_detail.html LoteDeMedio_list.html TipoDeMedio_detail_tablaCuadros.html
CuadroDeControl_detail_resumen.html LoteDeMedio_list_tabla.html TipoDeMedio_list.html
CuadroDeControl_detail_tablaMetodos.html MetodoDeControl_detail.html TipoDeMedio_list_tabla.html
LoteDeMedio_confirm_delete.html MetodoDeControl_detail_resumen.html dropdown_CuadroDeControl.html
LoteDeMedio_create.html TipoDeMedio_confirm_delete.html dropwdown_CuadroDeControl.html
LoteDeMedio_detail.html TipoDeMedio_detail.html
LoteDeMedio_detail_resumen.html TipoDeMedio_detail_resumen.html
Here is an example of a working view:
class TipoDeMedioDetailView(AreaCalidadMixin, DashboardMixin, DetailView):
model = TipoDeMedio
Note that my views do not explicitly set template_name. In my production
environment, all my views load just fine. Django's template loader knows that the corresponding template to the view is TipoDeMedio_detail.html
However, in my production environment, which is set up with apache2 and mod_wsgi on a Ubuntu 20.04.2 LTS x86_64 Linode VM, the template loader fails to load the template of the same view, because it searches for it in all lowercase. Here is an example:
Request Method: GET
Request URL: http://45.79.4.38/calidad/TipoDeMedio/lista
Django Version: 3.1.6
Exception Type: TemplateDoesNotExist
Exception Value:
calidad/tipodemedio_list.html
Exception Location: /home/jonatan/django-app/venv/lib/python3.8/site-packages/django/template/loader.py, line 47, in select_template
Python Executable: /home/jonatan/django-app/venv/bin/python
Python Version: 3.8.5
Python Path:
['/home/jonatan/django-app/mysite',
'/usr/lib/python38.zip',
'/usr/lib/python3.8',
'/usr/lib/python3.8/lib-dynload',
'/home/jonatan/django-app/venv/lib/python3.8/site-packages']
Server time: Mon, 21 Jun 2021 18:24:19 -0500
Template-loader postmortem
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.filesystem.Loader: /home/jonatan/django-app/mysite/templates/calidad/tipodemedio_list.html (Source does not exist)
django.template.loaders.app_directories.Loader: /home/jonatan/django-app/mysite/login/templates/calidad/tipodemedio_list.html (Source does not exist)
django.template.loaders.app_directories.Loader: /home/jonatan/django-app/venv/lib/python3.8/site-packages/django/contrib/admin/templates/calidad/tipodemedio_list.html (Source does not exist)
django.template.loaders.app_directories.Loader: /home/jonatan/django-app/venv/lib/python3.8/site-packages/django/contrib/auth/templates/calidad/tipodemedio_list.html (Source does not exist)
An easy fix is to manually specify my template_name attribute on each of my CBV and point to the correct case-sensitive template name (for instance TipoDeMedio_detail.html. However, I would really like to avoid that.
I'm just trying to understand what is the root cause of the change in behavior between the environments. It just leads me to believe I will encounter similar problems in other aspects of Django's behavior.
The default Apple File System (APFS) is not case sensitive. This means that during development on your Mac, Django was able to find templates even if the filenames used incorrect case.
Now that you have moved to Ubuntu, it uses a case-sensitive file system by default. Django is not able to find the templates if the case is wrong.
Note that the Django docs for class-based generic views state:
... in the absence of an explicit template Django will infer one from the object’s name ... is the lowercased version of the model’s name.
The preferable solution is to rename your templates using lowercase.
MattRowbum pointed out to me APFS isn't case sensitive. I consider this sufficient explanation for the change in behavior.
Issue Summary
Installed django-oscar sandbox app successfully but getting a small error in django-oscar/sandbox/urls.py at the line url(r'^', include(apps.get_app_config('oscar').urls[0])),
Error Message:
AttributeError: 'AppConfig' object has no attribute 'urls'
The 'apps' above is comming from django package:
from django.apps import apps
and using it in
url(r'^', include(apps.get_app_config('oscar').urls[0])),
I googled it but didn't find the solution. I am following the instuructions available on your official django-oscar website: https://django-oscar.readthedocs.io/en/releases-1.6/internals/sandbox.html to make the sandbox app up and running locally.
Technical details
Python version: 3.5.2
Django version:2.1.7
Oscar version: 1.6.7(django-oscar)
installed Django 1.6.1 over 1.5, update Pillow, PIL, django-ckeditor and django-ckeditor-updated, remove default from url. When I want to upload a picture I see this:
ImportError at /ckeditor/upload/
No module named image
Request Method: POST
Request URL: mysiteaddress/ckeditor/upload/?CKEditor=id_about&CKEditorFuncNum=1&langCode=en
Django Version: 1.6.1
Exception Type: ImportError
Exception Value:
No module named image
Exception Location: /usr/local/lib/python2.7/site-packages/ckeditor/image_processing.py in get_backend, line 10
Python Executable: /usr/local/bin/uwsgi
Python Version: 2.7.5
someone can help?
Along with trying collect static, you are not supposed to have django-ckeditor and django-ckeditor-updated in the same project. See installation notes.
https://github.com/shaunsephton/django-ckeditor#installation
Trying to create simple login functionality using Django, and I'm pretty new to using python and django. I've been searching for a while, but haven't found anything that fixes the problem. I'm running Django using MS VS2010, so I'm working under Windows instead of the typical linux environment. When run, I get this:
Request Method: GET
Request URL: http://localhost:1214/accounts/signup
Django Version: 1.4.3
Exception Type: ImportError
Exception Value:
No module named accounts
Exception Location: C:\Python27\lib\site-packages\django\utils\importlib.py in import_module, line 35
Python Executable: C:\Python27\python.exe
Python Version: 2.7.3
Python Path:
['C:\\Users\\brandon\\Desktop\\AdvancedLogin\\AdvancedLogin',
'C:\\Windows\\system32\\python27.zip',
'C:\\Python27\\DLLs',
'C:\\Python27\\lib',
'C:\\Python27\\lib\\plat-win',
'C:\\Python27\\lib\\lib-tk',
'C:\\Python27',
'C:\\Python27\\lib\\site-packages']
I've got the
__init__.py
file in bot the main project directory, and the app directory, though I haven't modified them at all.
I'm not really sure where to go from here. Any help is appreciated!
Did you add the accounts to your settings.py?
For other people be sure to use the correct AUTHENTICATION_BACKENDS. I've set up one for test but forgot it and i've got the same error.
Before i was :
settings.py
AUTHENTICATION_BACKENDS = (
'accounts.backends.MyAuthBackend',
)
After : settings.py
#Default one
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
)
This same error I was getting when I included 'accounts' in my setting.py file in "INSTALLED_APPS". But I was using sublime editor so I forgot to save that file and got this error.
Simply you have to add this "accounts" this to INSTALLED_APPS. this worked for me.
I tried to install django db log from here https://github.com/dcramer/django-db-log, by running python setup.py install, but for some reason when I add the app to the settings.py file, it's not working. here's the error that I get:
Request Method: GET
Request URL: http://localhost:8000/admin/
Django Version: 1.3.1
Exception Type: ImportError
Exception Value:
cannot import name Paginator
Exception Location: /Library/Python/2.6/site-packages/django/utils/importlib.py in import_module, line 35
Python Executable: /usr/bin/python
Python Version: 2.6.1
Python Path:
['/Users/christopherfarm/Desktop/ecomstore',
'/Library/Python/2.6/site-packages/python_dateutil-1.5-py2.6.egg',
'/Library/Python/2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg',
'/Library/Python/2.6/site-packages/django_db_log-2.2.1-py2.6.egg',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages',
'/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload',
'/Library/Python/2.6/site-packages',
'/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC',
'/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode']
Server time:
From the django-db-log's project page:
This project is no longer updated. Please see http://github.com/dcramer/django-sentry for its successor
So I simply assume that this project is not compatible with Django-1.3.1 due to various deprecations...