91๐
see http://django.readthedocs.org/en/latest/releases/1.7.html#standalone-scripts
import django
django.setup()
74๐
I had a similar (the same?) isssue when upgrading to Django 1.7. In may case, it was enough to update the wsgi file: replace
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
with
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
- [Django]-How to send email via Django?
- [Django]-Dynamically add field to a form
- [Django]-A better way to restart/reload Gunicorn (via Upstart) after 'git pull'ing my Django projects
22๐
I was looking through all these thread to get celery working on windows (with this particular error message) and I just want to emphasize putting
import django
django.setup()
at the top of your tasks.py file, this is finally what got it working for me.
- [Django]-Django 2, python 3.4 cannot decode urlsafe_base64_decode(uidb64)
- [Django]-Differences between STATICFILES_DIR, STATIC_ROOT and MEDIA_ROOT
- [Django]-How to change User representation in Django Admin when used as Foreign Key?
12๐
INSTALLED_APPS
Had an missing comma in the array, that caused the error for me.
- [Django]-Why is assertDictEqual needed if dicts can be compared by `==`?
- [Django]-AbstractUser vs AbstractBaseUser in Django?
- [Django]-Best way to integrate SqlAlchemy into a Django project
12๐
I got this error when I tried to import models from the appโs __init__.py
, which is not possible.
- [Django]-Effects of changing Django's SECRET_KEY
- [Django]-Is there a way to undo a migration on Django and uncheck it from the list of showmigrations?
- [Django]-Django: best practice way to get model from an instance of that model
6๐
In configuration uwsgi application file ( like uwsgi.ini ) replace:
module = django.core.handlers.wsgi:WSGIHandler()
on
module=django.core.wsgi:get_wsgi_application()
- [Django]-How to change status of JsonResponse in Django
- [Django]-Best practices for adding .gitignore file for Python projects?
- [Django]-Favorite Django Tips & Features?
1๐
settings.AUTH_USER_MODEL
is a string (thatโs why you get AttributeError: 'str' object has no attribute '_meta'
โ it expects a Model) and should be used only on ForeignKey
declarations:
class Article(models.Model): author = models.ForeignKey(settings.AUTH_USER_MODEL)
If you want to refer to your user model somewhere else you need to use get_user_model
:
from django.contrib.auth import get_user_model UserModel = get_user_model()
- [Django]-Django delete FileField
- [Django]-PyCharm: DJANGO_SETTINGS_MODULE is undefined
- [Django]-Django removing object from ManyToMany relationship
1๐
I got this error when moving to a different PC and forgetting to install psycopg2
in my venv and when using 'ENGINE': 'django.db.backends.postgresql',
in my settings.
Perhaps it can be useful to someone else.
- [Django]-Factory-boy create a list of SubFactory for a Factory
- [Django]-Ignoring Django Migrations in pyproject.toml file for Black formatter
- [Django]-Disable session creation in Django
- [Django]-How to get POST request values in Django?
- [Django]-Django Query That Get Most Recent Objects From Different Categories
- [Django]-Django: how to do calculation inside the template html page?
0๐
In my case, I forgot to add one of my sub-applications inside INSTALLED_APPS
.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'basketball',
'basketball.area',
'basketball.game',
'basketball.player',
]
- [Django]-Django: Safely Remove Old Migrations?
- [Django]-Redirect / return to same (previous) page in Django?
- [Django]-How to customize activate_url on django-allauth?
0๐
In my case the error was caused when I upgraded celery to 4.x and I had this in my INSTALLED_APPS: kombu.transport.django
. Removing that resolved the issue. Seems it is mostly caused by some incorrect load of django itself.
- [Django]-Detect django testing mode
- [Django]-How to produce a 303 Http Response in Django?
- [Django]-Django: list all reverse relations of a model
0๐
For those (like me) who are getting this error from shell:
Check that you are executing Djangoโs shell and not Pythonโs shell.
python manage.py shell
- [Django]-">", "<", ">=" and "<=" don't work with "filter()" in Django
- [Django]-Django โ Website Home Page
- [Django]-Django {% if forloop.first %} question
-3๐
Just reinstall Django using the command line, not in Pycharm helped to me.
- [Django]-"<Message: title>" needs to have a value for field "id" before this many-to-many relationship can be used.
- [Django]-Django REST Framework โ Separate permissions per methods
- [Django]-Django: best practice way to get model from an instance of that model