17👍
Go to django-ex/project/settings.py
Change the line in settings.py as below
WSGI_APPLICATION = 'application'
to WSGI_APPLICATION = 'wsgi.application'
That’s it 🙁
48👍
I used a middleware CorsMiddleware but forget to install it so after install, it works perfectly.
pip install django-cors-headers
So check something like it you may miss something like it.
- [Django]-How can I obtain the model's name or the content type of a Django object?
- [Django]-A Better Django Admin ManyToMany Field Widget
- [Django]-How can I apply a filter to a nested resource in Django REST framework?
30👍
Read carefully, it might say “The above exception was the direct cause of the following exception: …”. And the “above exception” being you forgot to install whitehoise. Run pip install whitenoise
, it worked for me.
- [Django]-The way to use background-image in css files with Django
- [Django]-Django DeleteView without confirmation template
- [Django]-How can I get the full/absolute URL (with domain) in Django?
16👍
If you run django project locally for development, just remove WSGI_APPLICATION variable from settings.py module. It needs in prod/stage settings, for example settings_prod.py
- [Django]-Make boolean values editable in list_display?
- [Django]-Django migrations – workflow with multiple dev branches
- [Django]-Django Blob Model Field
7👍
Do you have Django Debug Toolbar
Remove it and check if the problem goes away. Possible occurences:
pip uninstall django-debug-toolbar INSTALLED_APPS = [ ... 'debug_toolbar', ... ] MIDDLEWARE = [ ... 'debug_toolbar.middleware.DebugToolbarMiddleware', ... ]
- [Django]-<Django object > is not JSON serializable
- [Django]-Debugging Apache/Django/WSGI Bad Request (400) Error
- [Django]-Do I need Nginx with Gunicorn if I am not serving any static content?
6👍
This worked for me
Install this if you didn’t before:
pip install whitenoise
in settings.py add :
MIDDLEWARE = [
'whitenoise.middleware.WhiteNoiseMiddleware',
# ...
]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
- [Django]-Import data from excel spreadsheet to django model
- [Django]-Elegant setup of Python logging in Django
- [Django]-Django template if or statement
5👍
pip install whitenoise
Although solved my problem. Generally produced while we are moving a project to different virtual enviroments. Sometimes we forgot to install the package & whitenoise just broke the application little bit, because no where it is mentioned that you are missing "whitenoise" module.
- [Django]-Django multiprocessing and database connections
- [Django]-Error loading MySQLdb Module 'Did you install mysqlclient or MySQL-python?'
- [Django]-How can I embed django csrf token straight into HTML?
3👍
in settings.py file
change as follows:
WSGI_APPLICATION = ‘your_project_name.wsgi.application’
- [Django]-How to use if/else condition on Django Templates?
- [Django]-How to print line breaks in Python Django template
- [Django]-Why am I getting this error in Django?
3👍
note that any error in importing modules anywhere prior to starting the wsgi application will also prompt this message, so first look at the trace and start from the top in fixing issues.
I ported a Django app from python 2.7 to python3 and add all sorts of module import issues, not connected to this issue directly.
- [Django]-Multiple authentication backends configured and therefore must provide the `backend` argument or set the `backend` attribute on the user
- [Django]-XlsxWriter object save as http response to create download in Django
- [Django]-Get virtualenv's bin folder path from script
3👍
Check your middleware and delete error string
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
raise ImportError(
ImportError: Module "django.middleware.locale" does not define a "LocaleMiddlewarez" attribute/class
)
- [Django]-About 20 models in 1 django app
- [Django]-Necessity of explicit cursor.close()
- [Django]-Django and VirtualEnv Development/Deployment Best Practices
2👍
I was using django-cors-headers, then I thought I haven’t implemented cors in my project, so went ahead to install django-cors-middleware, then it’s started giving the wsgi exception, so i checked the stack trace and I found out that it’s django-cors-headers and django-cors-middleware conflicting each other. I had to uninstall django-cors-middleware but it’s still gives the same exception, so uninstall django-cors-headers too then reinstall and everything works fine….
- [Django]-Django – Overriding the Model.create() method?
- [Django]-Django storages aws s3 delete file from model record
- [Django]-ValueError: Dependency on app with no migrations: customuser
2👍
Same problem..
I checked whether django-cors-middleware and django-cors-headers installed or not. I found those were not installed and then I installed them.
- python -m pip install django-cors-middleware
- python -m pip install django-cors-headers
Then,
- python manage.py migrate
- python manage.py runserver
Finally, it’s worked….
- [Django]-When to create a new app (with startapp) in Django?
- [Django]-Using JSON in django template
- [Django]-How to add clickable links to a field in Django admin?
2👍
Go to settings.py
:
- In MIDDLEWARE, check whether you have added anything which is not working.
- In INSTALLED_APPS, check whether you have added the apps or not. If not, add all the apps you have created for this project.
Example: I had this error today and was totally unaware why is this happening then after checking for a while, I have found a very silly mistake e.g. I have added my newly created app in the MIDDLEWARE instead of INSTALLED_APPS.
- [Django]-Django 1.5b1: executing django-admin.py causes "No module named settings" error
- [Django]-In django do models have a default timestamp field?
- [Django]-How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi?
1👍
In the latest version of Django, to add your app in installed apps in settings.py
file, write –
[
….,
‘<appname>.apps.<Appname>Config
‘,
]
where <Appname>Config
is the name of the function in the apps.py
file.
- [Django]-Django form resubmitted upon refresh
- [Django]-Can I have a Django model that has a foreign key reference to itself?
- [Django]-How to aggregate (min/max etc.) over Django JSONField data?
1👍
You may not have entered your module name correctly in the setting.py or you may have added it incorrectly in wrong place like middleware…
- [Django]-Django MySQL error when creating tables
- [Django]-Django – iterate number in for loop of a template
- [Django]-How to change "app name" in Django admin?
0👍
I tried all these solution and the one worked for me was this:
pip install django-htmlmin
This module was missing and not mentioned in requirements.txt
Shows long error message that ends with wsgi application improperly configured. But somewhere in middle I could see "No module named 'htmlmin'
I installed and it is resolved.
- [Django]-Generic many-to-many relationships
- [Django]-Django Error u"'polls" is not a registered namespace
- [Django]-How to iterate over nested dictionaries in django templates
0👍
maybe using middleware is the simple way to fix this , this problem mostly happens about cors Policy
Code:
class CorsMiddleware(object):
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
return self.get_response(request)
def process_response(self,resp):
resp["Access-Control-Allow-Origin"] = "*"
return resp
- [Django]-Django gunicorn sock file not created by wsgi
- [Django]-PIL /JPEG Library: "decoder jpeg not available"
- [Django]-The view didn't return an HttpResponse object. It returned None instead
0👍
It happens when you insert something in MIDDLEWARE = [……]
solution tire to put added latest addend things at top of middleware.
- [Django]-Django connection to postgres by docker-compose
- [Django]-Does Django queryset values_list return a list object?
- [Django]-Load Multiple Fixtures at Once
0👍
You may also get this error while adding your custom middleware. While adding it, make sure you so it like this:
folder_contains_your_middleware_file.middleware_file.middleware_class
Below is my example:
'company_management.loginCheckMiddleware.LoginCheckMiddleware'
- [Django]-Annotating a Django queryset with a left outer join?
- [Django]-Detect mobile, tablet or Desktop on Django
- [Django]-Django admin page Removing 'Group'
0👍
I also had the same problem, in spite of trying all the above solutions I was facing the same issue.
I noticed that before this error I was getting the below error:
ModuleNotFoundError: No module named 'log_request_id'
To resolve this error I installed the django-log-request-id
package using pip install django-log-request-id
and both the issues got resolved.
- [Django]-Django ModelForm to have a hidden input
- [Django]-Django template how to look up a dictionary value with a variable
- [Django]-How to subquery in queryset in django?
0👍
I removed the custom middleware, but forgot to exclude it from MIDDLEWARES
in the settings.py
module, so be sure to verify that as well.
- [Django]-Django admin hangs (until timeout error) for a specific model when trying to edit/create
- [Django]-Django 3.x – which ASGI server (Uvicorn vs. Daphne)
- [Django]-Custom error messages in Django Rest Framework serializer
0👍
Inspecting the logs, the same error was thrown due to a "WhitenoiseMiddleware"
error, such as this.
The way to solve it was to make sure that WhiteNoiseMiddleware
is placed directly after the Django SecurityMiddleware
(if you are using it) and before all other middleware.
In settings.py
:
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware', # <-- here
# ...
]
Check the Django documentation for details.
- [Django]-How do you return 404 when resource is not found in Django REST Framework
- [Django]-Where is my Django installation?
- [Django]-Django model object with foreign key creation
0👍
It’s working for me
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware', # add only comma
]
My CORS Configuration
ALLOWED_HOSTS=['*']
CROS_ORIGIN_ALLOW_ALL = True
- [Django]-Django: FloatField or DecimalField for Currency?
- [Django]-Why second user login redirects me to /accounts/profile/ url in Django?
- [Django]-How should I use DurationField in my model?
0👍
As it turned out, in my case, the project dependency: django-request-logging
was not installed. This was resulting in the same error
pipenv install
installed the dependency and fixed the issue for me.
- [Django]-How do I restart celery workers gracefully?
- [Django]-Could not find a version that satisfies the requirement pkg-resources==0.0.0
- [Django]-Programmatically using Django's loaddata
- [Django]-Django custom field validator vs. clean
- [Django]-How do you dynamically hide form fields in Django?
- [Django]-Django – "Incorrect type. Expected pk value, received str" error
0👍
This is caused by a number of issues. Just confirm:
- If you are using gunicorn to server you django app ensure Whitenose is installed,and added to your middlewares and your gunicorn command lookes something like
gunicorn APP-NAME.wsgi:application --bind 0.0.0.0:8000 --timeout 120 --workers 2 --log-level info
and ensure your settings.py has something likeWSGI_APPLICATION = "APP-NAME.wsgi.application"
- If above is correct or you ain`t using gunicorn. Kindly check your middlewares. Most of the time you might have a middleware thats not installed that maybe blocking the server from starting.
- [Django]-Count number of records by date in Django
- [Django]-How to store a dictionary on a Django Model?
- [Django]-Add an object by id in a ManyToMany relation in Django
0👍
Try removing ‘django.contrib.auth.middleware.AuthenticationMiddleware’ from MIDDLEWARE. This worked for me when I had similar issue.
- [Django]-Disconnect signals for models and reconnect in django
- [Django]-Django-way for building a "News Feed" / "Status update" / "Activity Stream"
- [Django]-Django – exception handling best practice and sending customized error message
0👍
I would be surprised if that’s the case but personally I had the same error and the problem was just a typo in the middlewares, I wrote corseheaders (with an extra "e") instead of corsheaders
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
...
]
- [Django]-Get the file path for a static file in django code
- [Django]-Simple approach to launching background task in Django
- [Django]-Default value for user ForeignKey with Django admin
-1👍
Make sure you are in desired python Environment
Get the
requirements.txt
file or thepython modules list
, which are needed to execute django.
Install all the Modules and you shall be good to go.
- [Django]-Choose test database?
- [Django]-Django: accessing session variables from within a template?
- [Django]-How to implement a "back" link on Django Templates?