56👍
Most common cause of this is that you’re just running python
instead of using python manage.py shell
, which means you need to manually set the DJANGO_SETTINGS_MODULE
environment variable so Django knows where to find your settings (manage.py shell
does that for you automatically).
It’s also possible (but less common) that you have something that’s trying to import settings during the process of setting up your settings. To determine if that’s the case, look at your settings file for any imports or function calls that might need to access settings (including code in things being imported by your settings file).
8👍
For anyone still experiencing this issue with little resolve, Ensure the setdefault DJANGO_SETTINGS_MODULE is moved to the top of the script file.
import os
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_crazy_service.settings')
django.setup()
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application
disregard the squiggly marks
- [Django]-Count frequency of values in pandas DataFrame column
- [Django]-Non-primary foreign keys in Django
- [Django]-Django rest framework queryset doesn't order
- [Django]-Composite primary key in django
- [Django]-Giving email account a name when sending emails with Django through Google Apps
- [Django]-Django get list of models in application
3👍
Run python manage.py shell
instead of running python
to reach environment shell in your project. Python
does not simply recognize django
installed apps by default.
- [Django]-Uploading large files with Python/Django
- [Django]-Django form.as_p DateField not showing input type as date
- [Django]-Django Rest Framework: Disable field update after object is created
2👍
If you are using windows run
set DJANGO_SETTINGS_MODULE= <yourProjectName>.settings
(or) navigate to the folder containing settings file in terminal and run
set DJANGO_SETTINGS_MODULE=settings
- [Django]-Class Based Views VS Function Based Views
- [Django]-Django: ImproperlyConfigured: The SECRET_KEY setting must not be empty
- [Django]-PyCharm not recognizing Django project imports: from my_app.models import thing
- [Django]-How to use pdb.set_trace() in a Django unittest?
- [Django]-Celery task that runs more tasks
- [Django]-How to get the list of the authenticated users?
0👍
I saw this exception in the python console in pycharm when I run the following command,
from app_name.models import model_name
by the soloution present above, before this command, I used below command and the problem is solved
from project_name.wsgi import *
- [Django]-How does the get_or_create function in Django return two values?
- [Django]-Unable to connect to server: PgAdmin 4
- [Django]-ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.8/distutils/__init__.py)