61๐
This is what solved it for us and these folks:
Our project started with Django 1.4, we went to 1.5 and then to 1.7. Our wsgi.py looked like this:
import os
from django.core.handlers.wsgi import WSGIHandler
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
application = WSGIHandler()
When I updated to the 1.7 style WSGI handler:
import os
from django.core.wsgi import get_wsgi_application
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
application = get_wsgi_application()
Everything works now.
239๐
Running these commands solved my problem (credit to this answer):
import django
django.setup()
However Iโm not sure why I need this. Comments would be appreciated.
- [Django]-Django REST Framework: adding additional field to ModelSerializer
- [Django]-How to resize the new uploaded images using PIL before saving?
- [Django]-Create a field whose value is a calculation of other fields' values
58๐
The issue is in your registration app. It seems django-registration calls get_user_module()
in models.py
at a module level (when models are still being loaded by the application registration process). This will no longer work:
try:
from django.contrib.auth import get_user_model
User = get_user_model()
except ImportError:
from django.contrib.auth.models import User
Iโd change this models file to only call get_user_model()
inside methods (and not at module level) and in FKs use something like:
user = ForeignKey(settings.AUTH_USER_MODEL)
BTW, the call to django.setup()
shouldnโt be required in your manage.py
file, itโs called for you in execute_from_command_line
. (source)
- [Django]-Itertools.groupby in a django template
- [Django]-Django.contrib.gis.db.backends.postgis vs django.db.backends.postgresql_psycopg2
- [Django]-CORS error while consuming calling REST API with React
19๐
Just encountered the same issue. The problem is because of django-registration
incompatible with django 1.7 user model.
A simple fix is to change these lines of code, at your installed django-registration
module::
try:
from django.contrib.auth import get_user_model
User = get_user_model()
except ImportError:
from django.contrib.auth.models import User
to::
from django.conf import settings
try:
from django.contrib.auth import get_user_model
User = settings.AUTH_USER_MODEL
except ImportError:
from django.contrib.auth.models import User
Mine is at .venv/local/lib/python2.7/site-packages/registration/models.py
(virtualenv)
- [Django]-What is the use of PYTHONUNBUFFERED in docker file?
- [Django]-Factory-boy create a list of SubFactory for a Factory
- [Django]-Adding a user to a group in django
14๐
This works for me for Django 1.9 . The Python script to execute was in the root of the Django project.
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PROJECT_NAME.settings")
django.setup()
from APP_NAME.models import *
Set PROJECT_NAME and APP_NAME to yours
- [Django]-How can I call a custom Django manage.py command directly from a test driver?
- [Django]-What's the best solution for OpenID with Django?
- [Django]-Django REST framework post array of objects
5๐
Another option is that you have a duplicate entry in INSTALLED_APPS. That threw this error for two different apps I tested. Apparently itโs not something Django checks for, but then whoโs silly enough to put the same app in the list twice. Me, thatโs who.
- [Django]-Django: list all reverse relations of a model
- [Django]-Django: Why do some model fields clash with each other?
- [Django]-Django-allauth social account connect to existing account on login
3๐
Iโm damn sure this is isnโt late. If you are using Django 4
and .env
file for your settings, you are going to encounter this error if you define a value in settings.py while that value does not exist in .env
file:
See following scenario:
I had PLAID_KEY in my settings.py
as follows
PLAID_KEY=env('PLAID_KEY')
However, PLAID_KEY did not exist in my .env file, adding it fixed it.
- [Django]-Mixin common fields between serializers in Django Rest Framework
- [Django]-Strings won't be translated in Django using format function available in Python 2.7
- [Django]-Django character set with MySQL weirdness
2๐
Do you have a Python virtual environment that you need to enter before you run manage.py?
I ran into this error myself, and that was the problem.
- [Django]-Django: Redirect to previous page after login
- [Django]-Using Python's os.path, how do I go up one directory?
- [Django]-Setting Django up to use MySQL
2๐
I ran into this issue when I use djangocms and added a plugin (in my case: djangocms-cascade). Of course I had to add the plugin to the INSTALLED_APPS. But the order is here important.
To place โcmsplugin_cascadeโ before โcmsโ solved the issue.
- [Django]-In a django model custom save() method, how should you identify a new object?
- [Django]-Allowing RabbitMQ-Server Connections
- [Django]-Django celery task: Newly created model DoesNotExist
2๐
install django-registration-redux==1.1 instead django-registration, if you using django 1.7
- [Django]-Django models.py Circular Foreign Key
- [Django]-Is there a list of Pytz Timezones?
- [Django]-Group by Foreign Key and show related items โ Django
- [Django]-Filtering using viewsets in django rest framework
- [Django]-How can I chain Django's "in" and "iexact" queryset field lookups?
- [Django]-How to test "render to template" functions in django? (TDD)
0๐
If you get this error in a context of creating ForeignKey relations between models. Example below raises AppRegistryNotReady: Models aren't loaded yet
error.
from my_app.models import Workspace
workspace = models.ForeignKey(Workspace)
Then please try to reffer to a model as a string.
from my_app.models import Workspace
# One of these two lines might fix the problem.
workspace = models.ForeignKey('Workspace')
workspace = models.ForeignKey('my_app.Workspace')
- [Django]-ModuleNotFoundError: No module named 'grp' on windows
- [Django]-How to force application version on AWS Elastic Beanstalk
- [Django]-FileUploadParser doesn't get the file name
-1๐
Your manage.py
is โwrongโ; I donโt know where you got it from, but thatโs not a 1.7 manage.py
โ were you using some funky pre-release build or something?
Reset your manage.py
to the conventional, as below, and things Should Just Work:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
- [Django]-Django: using more than one database with inspectdb?
- [Django]-How to print BASE_DIR from settings.py from django app in terminal?
- [Django]-"gettext()" vs "gettext_lazy()" in Django
-1๐
My Problem was from init.py . i made an app and wanted to do this :
from MY_APP import myfunc
instead of :
from MY_APP.views import myfunc
when i rolled back my changes to these parts . everything worked just fine.
- [Django]-Add additional options to Django form select widget
- [Django]-Django: Record with max element
- [Django]-Google Static Maps URL length limit