Django Python manage.py migrate doesnt work - python

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

Related

django.core.exceptions.ImproperlyConfigured: Set the SECRET_KEY environment variable what you said in the previous question doesn't work

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

getting error cannot read file data: is a directory when making migration in django rest framework

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!)

AttributeError: function 'initGEOS_r' not found

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

eventlet.monkey_patch() throws an exception: The SECRET_KEY setting must not be empty

I have a Django project. The packages I use: Django 1.11, Eventlet 0.21.0. Python version is 3.4.3.
There are the following configuration files:
1) The main project's configuration file settings.py. It's main role to import one of the other's two configuration files.
try:
from .settings_local import *
except ImportError:
from .conf.common import *
2) settings_local.py. The purpose of this file to import all the settings from common.py and override those inside the file's body (or add some new settings) for example for testing purposes:
from .conf.common import *
...
3) common.py. The file that contains all the configurations settings.
import eventlet
eventlet.monkey_patch(all=True, MySQLdb=True)
...
When I try to check configuration I get the following error:
./manage.py check
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/core/management/base.py", line 322, in execute
saved_locale = translation.get_language()
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 195, in get_language
return _trans.get_language()
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 59, in __getattr__
if settings.USE_I18N:
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/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 "/vagrant/<project_name>/<project_name>/<project_name>/settings.py", line 2, in <module>
from .settings_local import *
File "/vagrant/<project_name>/<project_name>/<project_name>/settings_local.py", line 1, in <module>
from .conf.common import *
File "/vagrant/<project_name>/<project_name>/<project_name>/conf/common.py", line 3, in <module>
eventlet.monkey_patch(all=True, MySQLdb=True)
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/eventlet/patcher.py", line 254, in monkey_patch
_green_existing_locks()
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/eventlet/patcher.py", line 345, in _green_existing_locks
if isinstance(obj, rlock_type):
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/utils/functional.py", line 238, in inner
self._setup()
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/conf/__init__.py", line 129, in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
I figured out that an exception initially occurs in /lib/python3.4/site-packages/eventlet/patcher.py in a function _green_existing_locks() and then propagates up to __init.py__.
Could someone tell me what am I doing wrong?
Please observe the difference between settings and code.
# settings.py
SECRET_KEY = 'abc...'
DEBUG = True
# just a list of constant definitions
# your common.py
eventlet.monkey_patch()
# it's code that changes python environment
# another bad example of settings.py with similar problem
open('/tmp/flag-file-1', 'w')
os.remove('/tmp/flag-file-2')
you don't put side effect generating code into settings. Find a place for initialisation code according to Django guidelines for your version and place monkey_patch() there.
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting
must not be empty.
Following error signifies that SECRET_KEY is not set in settings

django Error: django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet

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

Categories