Python 3.4 Django 1.8 PythonAnywhere ImproperlyConfigured - python

Trying to deploy my project on pythonanywhere.
python3.4
Django 1.8.7
Username - GriMel
Project name - TwDTutor
wsgi configuration file
import os
import sys
path = '/home/GriMel/TwDTutor'
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'TwDTutor.settings'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Static files
/static/admin /home/GriMel/.virtualenvs/rango/lib/python3.4/site-packages/django/contrib/admin/static/admin
/static/ /home/GriMel/TwDTutor/rango/static
Get the error
django.core.exceptions.ImproperlyConfigured: Module "django.contrib.auth.middleware" does not define a "SessionAuthenticationMiddleware" attribute/class

That error usually indicates that there's a Django version mismatch so you probably haven't set the virtualenv correctly on the web app tab.

Related

Missing variable `handler` or `app` in file "project/wsgi.py"

I have been trying to deploy my Django app to Vercel and I am getting this error. Any idea?
Missing variable `handler` or `app` in file "qr_project/wsgi.py".
So I found out that vercel looks for app not application (which is comes default with django-admin startproject mysite). So I changed my wsgi.py file like this
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_project.settings')
application = get_wsgi_application()
app = application

After splitting settings.py file, mod_wsgi failed to exec Python script file. And application = get_wsgi_application() errors occured over and over

Hi everybody I tried to deploy my django project with apache, mod_wsgi in windows.
I splited my settings.py like this:
source root folder
project folder
apps
config
settings
init.py
base.py
local.py
prod.py
init.py
asgi.py
urls.py
wsgi.py
myenv
After I splited settings.py,
Mod_wsgi failed to exec python scripts file :
'C:/user/users/desktop/source_root_folder/project_folder/wsgi.py'.
Mod_wsgi also show the exception that Exception occurred processing WSGI script :
'C:/user/users/desktop/source_root_folder/project_folder/wsgi.py'
In Apache24 error log, 'C:/user/users/desktop/source_root_folder/project_folder/wsgi.py'
application = get_wsgi_application()
error occured.
# project_folder/wsgi.py
import os
from django.core.wsgi import get_wsgi_application
import sys
sys.path.append('C:/Apache24/htdocs/ C:/user/users/desktop/source_root_folder')
os.environ['DJANGO_SETTINGS_MODULE'] = 'project_folder.config.settings'
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project_folder.config.settings')
application = get_wsgi_application()
how can i deal with those errors?
please give me some helps.
you need to specify the *.py settings file:
os.environ['DJANGO_SETTINGS_MODULE'] = 'project_folder.config.settings.init'

502 occurs when creating environment on elastic beanstalk

I'm having an issue deploying my first Django project.
Here's my config.yml:
global:
application_name: testapp
branch: null
default_ec2_keyname: aws-eb
default_platform: Python 3.8 running on 64bit Amazon Linux 2
default_region: us-west-2
include_git_submodules: true
instance_profile: null
platform_name: null
platform_version: null
profile: eb-cli
repository: null
sc: null
workspace_type: Application
And here's my django.config:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: djangoproject.wsgi:application
I have followed this doc. But after I did eb create testapp-env, I get 502 error:
image of the error
I will provide further information if you need. Thank you in advance for your help.
Here's the error in web.stdout.log:
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
UPDATE
My django project uses python-socketio, and here's my wsgi.py:
from django.core.wsgi import get_wsgi_application
import socketio
from post.socketioserver import sio # <- it's just my socket io code
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoproject.settings')
django_app = get_wsgi_application()
application = socketio.WSGIApp(sio, django_app)
I get another error:
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
You need to set the DJANGO_SETTINGS_MODULE environment variable:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: djangoproject.wsgi:application
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: "djangoproject.settings"
Also you need to edit your wsgi.py file because you are accessing an app before Django setup:
import django
django.setup()
from django.core.wsgi import get_wsgi_application
import socketio
from post.socketioserver import sio # <- it's just my socket io code
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoproject.settings')
django_app = get_wsgi_application()
application = socketio.WSGIApp(sio, django_app)

Cannot deploy django on Apache with mod-wsgi

I have been working on a Django app that I am ready to move to the production server. I have Apache and mod_wsgi installed and I used a test to check to see that it all works, and it does. But now I am having problems getting it to work with Django.
I have created the wsgi.py file:
import os
import os.path
import sys
sys.path.append('/var/www/html/mideastinfo/lib/python2.7/site-packages/django/bin/mideastinfo')
#os.environ['PYTHON_EGG_CACHE'] = 'path to a directory for egg cache'
os.environ['DJANGO_SETTINGS_MODULE'] = 'mideastinfo.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandlers()
And I have the http.conf point to it via WGSIScriptAlias. It's not working, I know it has to do with the sys.path, I am not sure what to do.
I had a development environment in which I did all the build. Then, I installed all the project dependencies onto the server user pip and a requirements.txt. Then, I moved my project files over. But I think I am getting all the mapping and pathing wrong. Any ideas? I feel like I am one step away from being done with this.
I will share how I've configured a simple example:
import os,sys
apache_configuration = os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
sys.path.append('PATH TO YOUR PROJECT ROOT')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mideastinfo.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
On your VirtualHost directive on Apache config you must have:
WSGIScriptAlias / /PATH/TO/YOUR/.wsgi
Example:
<VirtualHost *:80>
ErrorLog /home/user/logs/error.log
...
WSGIScriptAlias / /PATH/TO/YOUR/.wsgi
...
</VirtualHost>

How to configure wsgi application to migrate to django 1.7?

I'm trying to upgrade from Django 1.6 to 1.7.
When running python manage.py runserver, I got the following error :
django.core.exceptions.ImproperlyConfigured: WSGI application 'myapp.wsgi.application' could not be loaded; Error importing module: 'cannot import name get_path_info'
Here's the corresponding line in my settings.py :
WSGI_APPLICATION = 'myapp.wsgi.application'
Here's my wsgi.py file :
import os
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "myapp.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
from dj_static import Cling
application = Cling(get_wsgi_application())
Any idea to fix it ?
What version of dj_static are you using?
I upgraded to Django 1.7 and my site broke, leading me to your question.
I checked my dj_static version (I had been using 0.0.5 and noticed that the latest release at the time of this writing is 0.0.6).
Upon updating dj_static, my site appears to be functioning properly under Django 1.7.

Categories