Unable to use mixins from drf-extensions - python

I have installed drf-extensions and imported it to my views. After that, I started getting below exception and I was not able to identify the root cause of this. Can someone explain me, what went wrong here pls?
> python .\manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework\settings.py", line 177, in import_from_string
return import_string(val)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
module = import_module(module_path)
File "C:\Users\gknath\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework_extensions\utils.py", line 6, in <module>
from rest_framework_extensions.key_constructor.constructors import (
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework_extensions\key_constructor\constructors.py", line 4, in <module>
from rest_framework_extensions.key_constructor import bits
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework_extensions\key_constructor\bits.py", line 3, in <module>
from django.db.models.sql.datastructures import EmptyResultSet
ImportError: cannot import name 'EmptyResultSet' from 'django.db.models.sql.datastructures'
(C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\db\models\sql\datastructures.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\gknath\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\gknath\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run
self.check(display_num_errors=True)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\core\management\base.py", line 392, in check
all_issues = checks.run_checks(
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\urls\resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\urls\resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\urls\resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\gknath\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\gknath\Desktop\python-django\testing_new_backend_model_modp\projects\urls.py", line 5, in <module>
from .api import router
File "C:\Users\gknath\Desktop\python-django\testing_new_backend_model_modp\projects\api.py", line 2, in <module>
from api.views import FactorViewSet, ProjectViewSet, FactorViewSet
File "C:\Users\gknath\Desktop\python-django\testing_new_backend_model_modp\api\views.py", line 3, in <module>
from rest_framework_extensions.mixins import NestedViewSetMixin
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework_extensions\mixins.py", line 1, in <module>
from rest_framework_extensions.cache.mixins import CacheResponseMixin
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework_extensions\cache\mixins.py", line 5, in <module>
class BaseCacheResponseMixin:
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework_extensions\cache\mixins.py", line 8, in BaseCacheResponseMixin
object_cache_key_func = extensions_api_settings.DEFAULT_OBJECT_CACHE_KEY_FUNC
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework\settings.py", line 225, in __getattr__
val = perform_import(val, attr)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework\settings.py", line 166, in perform_import
return import_from_string(val, setting_name)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework\settings.py", line 180, in import_from_string
raise ImportError(msg)
ImportError: Could not import 'rest_framework_extensions.utils.default_object_cache_key_func' for API setting 'DEFAULT_OBJECT_CACHE_KEY_FUNC'. ImportError: cannot import name 'EmptyResultSet' from 'django.db.models.sql.datastructures' (C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\db\models\sql\datastructures.py).
If I disable the extension import then I can run fine. I am using three models and have written serializers and trying to make an nested API using drf_extensions.

I guess the problem is related to this issue: https://github.com/chibisov/drf-extensions/issues/294
Temporary fix for me was to uninstall and install with:
pip install -U git+git://github.com/chibisov/drf-extensions.git#8001a440c7322be26bbe2d16f3a334a8b0b5860b

Related

I have a problem importing openai in Django for web application purposes

My python version is able to run open ai on its own, but when I tried to integrate it with Django I ran into the following issue:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1031, in _bootstrap_inner
self.run()
^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 968, in run
self._target(*self._args, **self._kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/core/management/commands/runserver.py", line 134, in inner_run
self.check(display_num_errors=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/core/management/base.py", line 475, in check
all_issues = checks.run_checks(
^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/core/checks/registry.py", line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/core/checks/urls.py", line 24, in check_resolver
return check_method()
^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/urls/resolvers.py", line 494, in check
for pattern in self.url_patterns:
^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/utils/functional.py", line 57, in __get__
res = instance.__dict__[self.name] = self.func(instance)
^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/urls/resolvers.py", line 715, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/utils/functional.py", line 57, in __get__
res = instance.__dict__[self.name] = self.func(instance)
^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/urls/resolvers.py", line 708, in urlconf_module
return import_module(self.urlconf_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 902, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/Users/matthewsetiawan/Desktop/Final Year Project/OpenCare/Main Project/OpenCare/loanhub/urls.py", line 21, in <module>
path('',include('authentication.urls')),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/urls/conf.py", line 38, in include
urlconf_module = import_module(urlconf_module)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 902, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/Users/matthewsetiawan/Desktop/Final Year Project/OpenCare/Main Project/OpenCare/authentication/urls.py", line 3, in <module>
from . import views
^^^^^^^^^^^^^^^^^^^
File "/Users/matthewsetiawan/Desktop/Final Year Project/OpenCare/Main Project/OpenCare/authentication/views.py", line 13, in <module>
import openai
^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/__init__.py", line 9, in <module>
from openai.api_resources import (
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_resources/__init__.py", line 1, in <module>
from openai.api_resources.completion import Completion # noqa: F401
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_resources/completion.py", line 4, in <module>
from openai.api_resources.abstract import DeletableAPIResource, ListableAPIResource
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_resources/abstract/__init__.py", line 3, in <module>
from openai.api_resources.abstract.api_resource import APIResource
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_resources/abstract/api_resource.py", line 4, in <module>
from openai import api_requestor, error, util
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_requestor.py", line 21, in <module>
import aiohttp
^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/aiohttp/__init__.py", line 6, in <module>
from .client import (
^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/aiohttp/client.py", line 34, in <module>
from yarl import URL
^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/yarl/__init__.py", line 1, in <module>
from ._url import URL, cache_clear, cache_configure, cache_info
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/yarl/_url.py", line 11, in <module>
from ._quoting import _Quoter, _Unquoter
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/yarl/_quoting.py", line 14, in <module>
from ._quoting_c import _Quoter, _Unquoter # type: ignore[misc]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "yarl/_quoting_c.pyx", line 1, in init yarl._quoting_c
ValueError: builtins.type size changed, may indicate binary incompatibility. Expected 904 from C header, got 896 from PyObject
I have not been able to find my issue anywhere else on the web as this module is relatively new, however could anyone give some insights on this issue. Perhaps it has something to do with setting.py file?

[Django rest_framework]Problems in using redis as Django DRF cache

I'm trying to open the redis cache for the rest framework.
My configuration seems to be correct.
When I run, it reports an error. As shown below:
Watching for file changes with StatReloader
Performing system checks...
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\rest_framework\settings.py", line 177, in import_from_string
return import_string(val)
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
module = import_module(module_path)
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\rest_framework_extensions\utils.py", line 6, in <module>
from rest_framework_extensions.key_constructor.constructors import (
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\rest_framework_extensions\key_constructor\constructors.py", line 4, in <module>
from rest_framework_extensions.key_constructor import bits
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\rest_framework_extensions\key_constructor\bits.py", line 3, in <module>
from django.db.models.sql.datastructures import EmptyResultSet
ImportError: cannot import name 'EmptyResultSet' from 'django.db.models.sql.datastructures' (C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\sql\datastructures.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run
self.check(display_num_errors=True)
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\base.py", line 392, in check
all_issues = checks.run_checks(
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\django\urls\resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\django\urls\resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\django\urls\resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "D:\C_项目相关\PythonWeb\TakeMeHome\TakeMeHome\urls.py", line 20, in <module>
from Website import views as views2
File "D:\C_项目相关\PythonWeb\TakeMeHome\Website\views.py", line 155, in <module>
class Cache_test(APIView,):
File "D:\C_项目相关\PythonWeb\TakeMeHome\Website\views.py", line 158, in Cache_test
#cache_response(timeout=60)
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\rest_framework_extensions\cache\decorators.py", line 38, in __init__
self.key_func = extensions_api_settings.DEFAULT_CACHE_KEY_FUNC
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\rest_framework\settings.py", line 220, in __getattr__
val = perform_import(val, attr)
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\rest_framework\settings.py", line 166, in perform_import
return import_from_string(val, setting_name)
File "C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\rest_framework\settings.py", line 180, in import_from_string
raise ImportError(msg)
ImportError: Could not import 'rest_framework_extensions.utils.default_cache_key_func' for API setting 'DEFAULT_CACHE_KEY_FUNC'. ImportError: cannot import name 'EmptyResultSet' from 'django.db.models.sql.datastructures' (C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\sql\datastructures.py).
**ImportError: Could not import 'rest_framework_extensions.utils.default_cache_key_func' for API setting 'DEFAULT_CACHE_KEY_FUNC'.
ImportError: cannot import name 'EmptyResultSet' from 'django.db.models.sql.datastructures' (C:\Users\HUANG\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\sql\datastructures.py).**
It's frustrating that I'm a beginner and a rookie, I can't fix it.
And I didn't find the answer on the Internet, I can only try to come here and ask for your help
version:
Django: 3.2.10
drf : 3.11
redis: 3.0.2 (windows release)
my settings:
CACHES = {
'default':{
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': 'redis://127.0.0.1:6379/0',## if redis server has passwd,
# "LOCATION": "password#redis://127. 0.0.1:6379",
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
}
},
}
#
REST_FRAMEWORK_EXTENSIONS = {
'DEFAULT_CACHE_KEY_FUNC':
'rest_framework_extensions.utils.default_cache_key_func'
}
#views.py Like this:
from Users.serializers import UserAddrModelSerializer
from rest_framework_extensions.cache.decorators import cache_response
class Cache_test(APIView,):
permission_classes = []
throttle_classes = (AnonRateThrottle, UserRateThrottle)
#cache_response(timeout=60)
def get(self, request, *args, **kwargs):
obj = UserAddress.objects.all()
result = UserAddrModelSerializer(instance=obj, many=True).data
return Response(result)
This particular error is caused by drf-extensions not being compatible yet with Django 3.1+. (drf-extensions is one of the dependencies of your app; also, you say you're using 3.2.10, but 3.2 is still under development; the latest released version as of writing is 3.1.1) I've found a commit to the drf-extensions project on GitHub solving this issue, but that has not found its way yet to a release.
Some of your options:
Check if you really need the dependency, and if not, uninstall it. Depending on your caching needs, simply using Django's built-in caching framework might suffice.
Incorporate the fix in that commit that I linked into your installation of that dependency (i.e. patch your library locally).
Downgrade your Django installation in the meantime to version 3.0 (as a last resort).

why my pip gives same error when i run Django server?

I updated the version of my pip but when I run every time any command with pip on terminal, it gives me the same error. Before I tried to create a django project and after some time when I run project it gives error. I don't know where I am going wrong.
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/bin/pip", line 8, in <module>
sys.exit(main())
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 73, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/commands/__init__.py", line 104, in create_command
module = importlib.import_module(module_path)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 17, in <module>
from pip._internal.cli.req_command import RequirementCommand, with_cleanup
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 22, in <module>
from pip._internal.req.constructors import (
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/req/__init__.py", line 10, in <module>
from .req_install import InstallRequirement
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/req/req_install.py", line 10, in <module>
import uuid
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/uuid.py", line 57, in <module>
_AIX = platform.system() == 'AIX'
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/platform.py", line 891, in system
return uname().system
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/platform.py", line 857, in uname
processor = _syscmd_uname('-p', '')
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/platform.py", line 613, in _syscmd_uname
output = subprocess.check_output(('uname', option),
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 411, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/run/__init__.py", line 145, in __new__
process = cls.create_process(command, stdin, cwd=cwd, env=env, shell=shell)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/run/__init__.py", line 121, in create_process
shlex.split(command),
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/shlex.py", line 311, in split
return list(lex)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/shlex.py", line 300, in __next__
token = self.get_token()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/shlex.py", line 109, in get_token
raw = self.read_token()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/shlex.py", line 140, in read_token
nextchar = self.instream.read(1)
AttributeError: 'tuple' object has no attribute 'read'
Every time it is the same error with pip. Please help me with this problem.

Unable to pass arguments in python3 class

Firstly, I created a class that has __init__() on it in models.py, as you can see below. And when I import it in my views.py, the vscode intellisense also shows that my class takes 4 arguments. But when I try to run the program, it shows me an error saying that the class doesn't take any arguments. Any help would be appreciated, ty.
models.py:
from django.db import models
class destination:
def __init__(self, name, desc, price, img):
self.name = name
self.desc = desc
self.price = price
self.img = img
views.py:
from django.shortcuts import render
from .models import destination
dest1 = destination('Bali', 'Nice place to visit', 1000, 'destination_1.jpg')
dest2 = destination('Mumbai', 'The city that never sleeps', 500, 'destination_2.jpg')
dest3 = destination('Sylhet', 'The city of tea', 100, 'destination_3.jpg')
dests = [dest1, dest2, dest3]
def travello(req):
return render(req, 'index.html', {'dests': dests})
When I run python3 manage.py runserver:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 60, in execute
super().execute(*args, **options)
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 95, in handle
self.run(**options)
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/usr/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/core/management/base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/core/management/base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/urls/resolvers.py", line 398, in check
for pattern in self.url_patterns:
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/urls/resolvers.py", line 571, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/urls/resolvers.py", line 564, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/adnanbadshah/telusko/telusko/urls.py", line 21, in <module>
path('', include('travello.urls'))
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/adnanbadshah/telusko/travello/urls.py", line 1, in <module>
from . import views
File "/home/adnanbadshah/telusko/travello/views.py", line 6, in <module>
dest1 = destination('Bali', 'Nice place to visit', 1000, 'destination_1.jpg')
TypeError: destination() takes no arguments
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/utils/autoreload.py", line 579, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/utils/autoreload.py", line 564, in start_django
reloader.run(django_main_thread)
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/utils/autoreload.py", line 272, in run
get_resolver().urlconf_module
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/urls/resolvers.py", line 564, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/adnanbadshah/telusko/telusko/urls.py", line 21, in <module>
path('', include('travello.urls'))
File "/home/adnanbadshah/test/lib/python3.7/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/adnanbadshah/telusko/travello/urls.py", line 1, in <module>
from . import views
File "/home/adnanbadshah/telusko/travello/views.py", line 6, in <module>
dest1 = destination('Bali', 'Nice place to visit', 1000, 'destination_1.jpg')
TypeError: destination() takes no arguments
Running your Code snipped like it is works for me and the code snipped doesn't really tell the problem, so I expect you import another destination at some point, that you did not provide in your snipped or is hidden behind another import. I would recommend renaming your class e.g. Destination (using upper letter is the recommended way to write class names anyways) and see if that solves your problem.

Cannot Import Model Name Django with User Model and Informational Model

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x105de5048>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py", line 248, in raise_last_exception
raise _exception[1]
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py", line 337, in execute
autoreload.check_errors(django.setup)()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/apps/registry.py", line 112, in populate
app_config.import_models()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/Name/Desktop/ProjectDevCode/Restructured/mysite/seasons/models.py", line 2, in <module>
from users.models import User
File "/Users/Name/Desktop/ProjectDevCode/Restructured/mysite/users/models.py", line 11, in <module>
from seasons.models import Seasons
ImportError: cannot import name 'Seasons'
I randomly got this error in my recent django app. I am not sure why. The models import in other apps/files in my project. Any help is appreciated.
I believe you faced circular model import. Seems like you are importing User into seasons.model and Seasons into users.model.
If you use them as a foreign key you can set it as:
user = models.ForeignKey('users.User')

Categories