Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\apps\registry.py", line 122, in populate
app_config.ready()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\contrib\admin\apps.py", line 24, in ready
self.module.autodiscover()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\contrib\admin\__init__.py", line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\module_loading.py", line 47, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "C:\Users\HP\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\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\contrib\gis\admin\__init__.py", line 5, in <module>
from django.contrib.gis.admin.options import GeoModelAdmin, OSMGeoAdmin
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\contrib\gis\admin\options.py", line 2, in <module>
from django.contrib.gis.admin.widgets import OpenLayersWidget
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\contrib\gis\admin\widgets.py", line 4, in <module>
from django.contrib.gis.geos import GEOSException, GEOSGeometry
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\contrib\gis\geos\__init__.py", line 5, in <module>
from .collections import ( # NOQA
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\contrib\gis\geos\collections.py", line 8, in <module>
from django.contrib.gis.geos.geometry import GEOSGeometry, LinearGeometryMixin
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\contrib\gis\geos\geometry.py", line 17, in <module>
from django.contrib.gis.geos.prototypes.io import (
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\contrib\gis\geos\prototypes\io.py", line 212, in <module>
class WKBWriter(IOBase):
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\contrib\gis\geos\prototypes\io.py", line 216, in WKBWriter
geos_version = geos_version_tuple()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\contrib\gis\geos\libgeos.py", line 174, in geos_version_tuple
return get_version_tuple(geos_version().decode())
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\contrib\gis\geos\libgeos.py", line 169, in geos_version
return lgeos.GEOSversion()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\functional.py", line 224, in inner
self._setup()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\functional.py", line 360, in _setup
self._wrapped = self._setupfunc()
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\contrib\gis\geos\libgeos.py", line 66, in load_geos
_lgeos.initGEOS_r.restype = CONTEXT_PTR
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 382, in __getattr__
func = self.__getitem__(name)
File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 387, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'initGEOS_r' not found
I get AttributeError: function 'initGEOS_r' not found error while trying to run my server.
I am trying to write a basic Geo Django program
I have Postgres and GEOS also installed
I have also included GEOS and GDAL paths in my settings.py file.
I have tried all possible way to resolve this error but couldn't.
Can Someone Help me out!
I had the same problem this worked for me:
On settings.py write:
GDAL_LIBRARY_PATH = r'C:\OSGeo4W64\bin\gdal204'
GEOS_LIBRARY_PATH = r'C:\OSGeo4W64\bin\geos_c.dll'
PROJ_LIBRARY_PATH = r'C:\OSGeo4W64\share\proj'
On settings.py INSTALLED_APPS code:
'django.contrib.gis',
Add postgis to backend
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'xxx',
'USER': 'yyy',
'PASSWORD': 'xxx',
'HOST': '',
'PORT': '1234',
}
}
Remember that your models should inherit from
from django.contrib.gis.db import models
I hope this can help you
Same steps as the answer above, but on the M1 Macs, the settings looked like this:
GDAL_LIBRARY_PATH = "/opt/homebrew/lib/libgdal.dylib"
GEOS_LIBRARY_PATH = "/opt/homebrew/lib/libgeos_c.dylib"
(Didn't need PROJ because I'm using "ENGINE": "django.contrib.gis.db.backends.mysql",
Related
I can not run the project, I did what I was told in README.md as directed, but still gives an error.
The Output is:
Traceback (most recent call last):
File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\environ\environ.py", line 403, in get_value
value = self.ENVIRON[var_name]
~~~~~~~~~~~~^^^^^^^^^^
File "<frozen os>", line 678, in __getitem__
KeyError: 'SECRET_KEY'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\new-folder\manage.py", line 21, in <module>
main()
File "C:\new-folder\manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
utility.execute()
File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\core\management\__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\core\management\base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\core\management\base.py", line 448, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\core\management\base.py", line 93, in wrapped
saved_locale = translation.get_language()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\utils\translation\__init__.py", line 210, in get_language
return _trans.get_language()
^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\utils\translation\__init__.py", line 65, in __getattr__
if settings.USE_I18N:
^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\conf\__init__.py", line 92, in __getattr__
self._setup(name)
File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\conf\__init__.py", line 79, in _setup
self._wrapped = Settings(settings_module)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\django\conf\__init__.py", line 190, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\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 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\new-folder\usn_uchet\settings.py", line 26, in <module>
SECRET_KEY = ENV.str('SECRET_KEY')
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\environ\environ.py", line 213, in str
value = self.get_value(var, cast=str, default=default)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\environ\environ.py", line 407, in get_value
raise ImproperlyConfigured(error_msg) from exc
django.core.exceptions.ImproperlyConfigured: Set the SECRET_KEY environment variable
settings.py file
import os
import environ
from pathlib import Path
from django.utils.log import DEFAULT_LOGGING
import urllib3
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
ENV = environ.Env(DEBUG=(bool, True))
ENV_FILE = Path(os.path.join(BASE_DIR, '.env'))
if ENV_FILE.exists():
environ.Env.read_env(os.path.join(BASE_DIR, '.env'))
DEBUG = ENV.bool('DEBUG', True)
LOGLEVEL = ENV.str('LOGLEVEL', 'INFO')
SECRET_KEY = ENV.str('SECRET_KEY')
CRYPTO_KEY = bytes(ENV.str('CRYPTO_KEY'), 'UTF-8')
ALLOWED_HOSTS = ENV.list('ALLOWED_HOSTS', default=[])
.env file
DEBUG=on
SECRET_KEY=My_key
and how do I fix this error to start the server ?
what to do to get rid of this error tried to remove the space, also added to the directory where the settings.py.what you said in the previous question doesn't work
hi i am making an app which takes a users location and compares it with other people to find the distance. When i added a installed gdal geos postgis and proj4 i then added a pointfield from
from django.contrib.gis.db import models
then i did a migration and it returned an error of
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/home/aarush/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/home/aarush/anaconda3/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run
autoreload.raise_last_exception()
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/home/aarush/anaconda3/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/aarush/git_fudo/food1_back/food1_back/posts_v1/models.py", line 1, in <module>
from django.contrib.auth.base_user import BaseUserManager
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/contrib/auth/base_user.py", line 48, in <module>
class AbstractBaseUser(models.Model):
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/db/models/base.py", line 122, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/db/models/base.py", line 326, in add_to_class
value.contribute_to_class(cls, name)
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/db/models/options.py", line 206, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/db/__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/db/utils.py", line 214, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/db/utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "/home/aarush/anaconda3/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 6, in <module>
from .features import DatabaseFeatures
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/contrib/gis/db/backends/postgis/features.py", line 1, in <module>
from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/contrib/gis/db/backends/base/features.py", line 3, in <module>
from django.contrib.gis.db import models
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/contrib/gis/db/models/__init__.py", line 3, in <module>
import django.contrib.gis.db.models.functions # NOQA
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/contrib/gis/db/models/functions.py", line 3, in <module>
from django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/contrib/gis/db/models/fields.py", line 3, in <module>
from django.contrib.gis import forms, gdal
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/contrib/gis/forms/__init__.py", line 3, in <module>
from .fields import ( # NOQA
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/contrib/gis/forms/fields.py", line 2, in <module>
from django.contrib.gis.gdal import GDALException
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/contrib/gis/gdal/__init__.py", line 28, in <module>
from django.contrib.gis.gdal.datasource import DataSource
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/contrib/gis/gdal/datasource.py", line 39, in <module>
from django.contrib.gis.gdal.driver import Driver
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/contrib/gis/gdal/driver.py", line 5, in <module>
from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/contrib/gis/gdal/prototypes/ds.py", line 9, in <module>
from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
File "/home/aarush/anaconda3/lib/python3.7/site-packages/django/contrib/gis/gdal/libgdal.py", line 50, in <module>
lgdal = CDLL(lib_path)
File "/home/aarush/anaconda3/lib/python3.7/ctypes/__init__.py", line 364, in __init__
self._handle = _dlopen(self._name, mode)
OSError: /home/aarush/git_fudo/food1_back/food1_back: cannot read file data: Is a directory
to basically summarise this it is saying
cannot read file data: Is a directory
is there something i am missing?
(if you need anymore data about my project feel free to ask!)
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).
I am getting an error in Django. I saw a lot of similar questions but am not able to find a working solution. I think the error is in importing the User model. I am not able to find a solution to this. Basically, it seems that it is not able to get the User model. Please help.
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "C:\Python34\lib\site-packages\django\core\management\commands\runserver.py", line 113, in inner_run
autoreload.raise_last_exception()
File "C:\Python34\lib\site-packages\django\utils\autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "C:\Python34\lib\site-packages\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\Python34\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "C:\Python34\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Python34\lib\site-packages\django\apps\registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "C:\Python34\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "C:\Python34\lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "E:\Python\TheRandomSite\investor\__init__.py", line 1, in <module>
from . import urls
File "E:\Python\TheRandomSite\investor\urls.py", line 18, in <module>
from . import views
File "E:\Python\TheRandomSite\investor\views.py", line 4, in <module>
from investor.models import Game
File "E:\Python\TheRandomSite\investor\models.py", line 3, in <module>
from django.contrib.auth.models import User
File "C:\Python34\lib\site-packages\django\contrib\auth\models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Python34\lib\site-packages\django\contrib\auth\base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "C:\Python34\lib\site-packages\django\db\models\base.py", line 105, in __new__
app_config = apps.get_containing_app_config(module)
File "C:\Python34\lib\site-packages\django\apps\registry.py", line 237, in get_containing_app_config
self.check_apps_ready()
File "C:\Python34\lib\site-packages\django\apps\registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Thanks.
Try this
Make investor/__init__.py as empty, Then
include('investor.urls')
I'm having trouble with installing django. This is what I got. I only installed python and django. didnt change any files, there is an error that come out
(myvenv) C:\Users\admin\Desktop\smat>manage.py migrate
Traceback (most recent call last):
File "C:\Users\admin\Desktop\smat\manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\admin\Desktop\smat\myvenv\lib\site-packages\django\core\managem
ent\__init__.py", line 350, in execute_from_command_line
utility.execute()
File "C:\Users\admin\Desktop\smat\myvenv\lib\site-packages\django\core\managem
ent\__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\admin\Desktop\smat\myvenv\lib\site-packages\django\core\managem
ent\__init__.py", line 195, in fetch_command
klass = load_command_class(app_name, subcommand)
File "C:\Users\admin\Desktop\smat\myvenv\lib\site-packages\django\core\managem
ent\__init__.py", line 39, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "C:\Users\admin\AppData\Local\Programs\Python\Python35-32\lib\importlib\_
_init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 662, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "C:\Users\admin\Desktop\smat\myvenv\lib\site-packages\django\core\managem
ent\commands\migrate.py", line 16, in <module>
from django.db.migrations.autodetector import MigrationAutodetector
File "C:\Users\admin\Desktop\smat\myvenv\lib\site-packages\django\db\migration
s\autodetector.py", line 13, in <module>
from django.db.migrations.questioner import MigrationQuestioner
File "C:\Users\admin\Desktop\smat\myvenv\lib\site-packages\django\db\migration
s\questioner.py", line 12, in <module>
from .loader import MigrationLoader
File "C:\Users\admin\Desktop\smat\myvenv\lib\site-packages\django\db\migration
s\loader.py", line 10, in <module>
from django.db.migrations.recorder import MigrationRecorder
File "C:\Users\admin\Desktop\smat\myvenv\lib\site-packages\django\db\migration
s\recorder.py", line 12, in <module>
class MigrationRecorder(object):
File "C:\Users\admin\Desktop\smat\myvenv\lib\site-packages\django\db\migration
s\recorder.py", line 26, in MigrationRecorder
class Migration(models.Model):
File "C:\Users\admin\Desktop\smat\myvenv\lib\site-packages\django\db\migration
s\recorder.py", line 27, in Migration
app = models.CharField(max_length=255)
File "C:\Users\admin\Desktop\smat\myvenv\lib\site-packages\django\db\models\fi
elds\__init__.py", line 1072, in __init__
super(CharField, self).__init__(*args, **kwargs)
File "C:\Users\admin\Desktop\smat\myvenv\lib\site-packages\django\db\models\fi
elds\__init__.py", line 166, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "C:\Users\admin\Desktop\smat\myvenv\lib\site-packages\django\conf\__init_
_.py", line 55, in __getattr__
self._setup(name)
File "C:\Users\admin\Desktop\smat\myvenv\lib\site-packages\django\conf\__init_
_.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "C:\Users\admin\Desktop\smat\myvenv\lib\site-packages\django\conf\__init_
_.py", line 116, in __init__
setattr(self, setting, setting_value)
File "C:\Users\admin\Desktop\smat\myvenv\lib\site-packages\django\conf\__init_
_.py", line 85, in __setattr__
raise ImproperlyConfigured("If set, %s must end with a slash" % name)
django.core.exceptions.ImproperlyConfigured: If set, STATIC_URL must end with a
slash
How do I deal with it?? please help) Cant post my question, because it asks for more information, but to me there is no additional info
The error says your STATIC_URL value doesn't end with a slash. Checking your settings.py file and make sure it has a slash at the end of the value - a forward slash.
STATIC_URL = '/static/'
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")
This is exact copy of static in settings.py