Static Files not served via Apache for Django Application - django

I have spend the entire day on this. I couldn't get my static files served. My Django application is working fine. I am using: Python 3.4, Django 1.8.13, mod_wsgi 4.5.2. I have solved most of the errors in my httpd.conf using other questions in SO. What more is required to make this work.
httpd.conf
ServerRoot "/home/rajkumar2014/webapps/allure/apache2"
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule wsgi_module modules/mod_wsgi.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule alias_module modules/mod_alias.so
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog /home/rajkumar2014/logs/user/access_allure.log combined
ErrorLog /home/rajkumar2014/logs/user/error_allure.log
Listen 21188
KeepAlive Off
SetEnvIf X-Forwarded-SSL on HTTPS=1
ServerLimit 1
StartServers 1
MaxRequestWorkers 5
MinSpareThreads 1
MaxSpareThreads 3
ThreadsPerChild 5
WSGIRestrictEmbedded On
WSGILazyInitialization On
<VirtualHost *:21188>
Alias /media "/home/webapps/allure_media"
Alias /static "/home/webapps/allure_static"
<Directory /home/rajkumar2014/webapps/allure_media>
Require all granted
</Directory>
<Directory /home/rajkumar2014/webapps/allure_static>
Require all granted
</Directory>
WSGIDaemonProcess allure processes=2 threads=12 python-path=/home/rajkumar2014/webapps/allure/allure:/home/rajkumar2014/webapps/allure/lib/python3.4/site-packages:/home/rajkumar2014/webapps/allure/lib/python3.4
WSGIProcessGroup allure
WSGIScriptAlias / /home/rajkumar2014/webapps/allure/allure/allure/wsgi.py
<Directory /home/rajkumar2014/webapps/allure/apache2>
Require all granted
</Directory>
</VirtualHost>
settings.py
STATIC_URL = '/static/'
STATIC_ROOT = '/home/rajkumar2014/webapps/allure_static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)
# Media files (All user uploaded content)
MEDIA_ROOT = '/home/rajkumar2014/webapps/allure_media/'
MEDIA_URL = '/media/'
Kindly help.

i'm new to djano/python myself and fought this battle last month for my first django app ... im not a server admin so i can't say what exactly you're doing wrong but it seems your syntax is bit different than what i did , i have it like
Alias /static/ /home/ksjdsd3/public_html/mysite/static/
<Directory /home/ksjdsd3/public_html/mysite/static>
Require all granted
</Directory>
most notably there is a / after static and path to directory is not in the quotation

I used to have trouble serving static file with Webfaction, depending on the way I was installing Django (using the webfaction installer you can setup either a full django app or just an apache/mod_wsgi app where you can deploy your django release).
Webfaction has an extra nginx process running at root level for serving static files. So you should check the access control lists - ACLs.
For me this ACLs used to be the problem, nginx user had no read access to the static folder.
So maybe you can login to UNIX terminal on webfaction and run getfacl (you should get something similar to this output):
[rajkumar2014#webXXX ~]$getfacl /home/rajkumar2014/webapps/allure_static/
# file: home/rajkumar2014/webapps/allure_static/
# owner: rajkumar2014
# group: rajkumar2014
user::rwx
user:apache:r-x
user:nginx:r-x
group::rwx
mask::rwx
other::r-x
[rajkumar2014#webXXX ~]$ getfacl /home/rajkumar2014/webapps/allure/allure/allure/wsgi.py
getfacl: Removing leading '/' from absolute path names
# file: home/rajkumar2014/webapps/allure/allure/allure/wsgi.py
# owner: rajkumar2014
# group: rajkumar2014
user:apache:r-x
user:nginx:r-x
group::rw-
mask::rwx
other::--
The ideea is that the apache user and the nginx user should have read access to your static folder and also to the wsgi.py (if it was uploaded from an external source - your laptop).
Also check for errors and references to your static folder in the logs:
Frontend Logs, the nginx process serving static; location:
/home/rajkumar2014/logs/frontend/
User Logs, for user installed applications (like Django)
/home/rajkumar2014/logs/user/
I would be interested to know:
did you use the Webfaction Django installer?
did you create a webfaction app to serve static assets?
can you find references to your static folder in the frontend logs?
you have an old (Centos 6.5, Apache 2.2) or new (Centos 7, Apache 2.4) Webfaction plan?
More about this in the Webfaction Docs

Related

Django Image is not added to media folder

So the thing is that in production code with media files is not working (image of model is not added there). If you need some details please write! Thank you for your help )
project configuration
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
Alias /static /home/artashes/multi/static
<Directory /home/artashes/multi/static>
Require all granted
</Directory>
Alias /media /home/artashes/multi/media
<Directory /home/artashes/multi/static>
Require all granted
</Directory>
<Directory /home/artashes/multi/multisad>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/artashes/multi/multisad/wsgi.py
WSGIDaemonProcess django_app python-path=/home/artashes/multi python-home=/home/artashes/multi/venv
WSGIProcessGroup django_app
</VirtualHost>
settings
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
By the way I am using apache2 with linode server

Static files not being served on AWS Lightsail

After 2 days of trying multiple tutorials & reading StackOverflow, I'm calling for help!
The setting:
The development version is running smoothly on the AWS Lightsail server. It's during the production deployment that I'm running in continuous problems with the static files. The application runs on the appointed subdomain but it's missing all the JS/CSS/images/...
I have followed the official docs but to no avail.
1/ https://docs.bitnami.com/aws/infrastructure/django/get-started/deploy-django-project/
2/ https://docs.bitnami.com/aws/infrastructure/django/get-started/deploy-django-project/
My Folder Tree with relevant files:
Project
- conf
- httpd-app.conf
- httpd-prefix.conf
- Django2Tutorial
- settings.py
- wsgi.py
- Solar
- static
- static (after running collectstatic function in terminal,-it includes the admin, Solar statics)
My settings:
STATIC_ROOT = os.path.join(BASE_DIR,'static')
STATIC_URL = '/static/'
DEBUG = False
ALLOWED_HOSTS = ['54.169.172.***']
wsgi.py file
import os
import sys
sys.path.append('/opt/bitnami/apps/django/django_projects/Project')
os.environ.setdefault("PYTHON_EGG_CACHE", "/opt/bitnami/apps/django/django_projects/Project/egg_cache")
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'DjangoTutorial2.settings')
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
My conf files :
1. httpd-app.conf file
<IfDefine !IS_DJANGOSTACK_LOADED>
Define IS_DJANGOSTACK_LOADED
WSGIDaemonProcess wsgi-djangostack processes=2 threads=15 display-name=%{GROUP}
</IfDefine>
<Directory "/opt/bitnami/apps/django/django_projects/Project/DjangoTutorial2">
Options +MultiViews
AllowOverride All
<IfVersion >= 2.3>
Require all granted
</IfVersion>
WSGIProcessGroup wsgi-djangostack
WSGIApplicationGroup %{GLOBAL}
</Directory>
Alias /static "/opt/bitnami/apps/django/django_projects/Project/static"
<Directory "/opt/bitnami/apps/django/django_projects/Project/static">
Require all granted
</Directory>
WSGIScriptAlias / '/opt/bitnami/apps/django/django_projects/Project/DjangoTutorial2/wsgi.py'
2. httpd-prefix.conf file
# Include file
RewriteEngine On
RewriteCond "%{HTTP_HOST}" ^ec2-([0-9]{1,3})-([0-9]{1,3})-([0-9]{1,3})-([0-9]{1,3})\..*\.amazonaws.com(:[0-9]*)?$
RewriteRule "^/?(.*)" "%{REQUEST_SCHEME}://%1.%2.%3.%4%5/$1" [L,R=302,NE]
Include "/opt/bitnami/apps/django/django_projects/Project/conf/httpd-app.conf"
Other adjustments made: (/opt/bitnami/apache2/conf/bitnami)
1/ bitnami-apps-prefix.conf file
Include "/opt/bitnami/apps/django/django_projects/Project/conf/httpd-prefix.conf"
2/ bitnami.conf file
VirtualHost _default_:80>
WSGIScriptAlias / /opt/bitnami/apps/django/django_projects/Project/DjangoTutorial2/wsgi.py
<Directory /opt/bitnami/apps/django/django_projects/Project>
AllowOverride all
Require all granted
Options FollowSymlinks
</Directory>
DocumentRoot /opt/bitnami/apps/django/django_projects/Project
</VirtualHost>
the bitnami-apps-vhosts.conf file is empty? Can this be?
Checked as well:
restarted Apache on multiple occasions
played around with the static_url & static_roots
Can anyone advise how to proceed? It's been extremely frustrating 2 days haha.
Note, maybe this can help :
double-checked with the findstatic function, it redirects me to the Solar/static folder. I thought since I ran collect static, I should point to the Project level static folder in the apache conf & not the Solar level static folder.
You need to add Alias /static/ /opt/bitnami/apps/django/django_projects/Project/static/ to your virtualhost config so the server knows to map /static/ requests to that folder.
I wasted A LOT of time on this, here's my final working bitnami.conf file.
<VirtualHost _default_:80>
WSGIDaemonProcess django_site python-home=/opt/bitnami/projects/env python-path=/opt/bitnami/projects/django_site.com
WSGIProcessGroup django_site
WSGIScriptAlias / /opt/bitnami/projects/django_site.com/django_site/wsgi.py
<Directory /opt/bitnami/projects/django_site.com>
AllowOverride all
Require all granted
Options FollowSymlinks
WSGIProcessGroup django_site
</Directory>
Alias /static/ /opt/bitnami/projects/django_site.com/static/
</VirtualHost>
Include "/opt/bitnami/apache/conf/bitnami/bitnami-ssl.conf"
Note:
I know it's not recommended, but I put all the codes inside bitnami.conf and neglected httpd-app.conf and httpd-prefix.conf
I created python virtualenv at /opt/bitnami/projects/env and installed all needed libraries there
I added the below code to my settings.py file before running python manage.py collectstatic
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

Deploy django-channels with Apache2 and Daphne

I'm trying to learn to use django-channels and have worked through both the tutorial and this multichat example. I am now trying to deploy it on a Digital Ocean droplet using Apache and Daphne. I would happily use Daphne by itself but I do not understand how to.
So this is my Apache conf file:
<VirtualHost *:80>
ServerAdmin webmaster#mysite.co.uk
ServerName multichat.mysite.co.uk
ServerAlias www.multichat.mysite.co.uk
DocumentRoot /var/www/multichat
WSGIDaemonProcess multichat python-path=/var/www/multichat python-home=/var/www/multichat/env
WSGIProcessGroup multichat
WSGIScriptAlias / /var/www/multichat/multichat/wsgi.py
Alias /robots.txt /var/www/multichat/static/robots.txt
Alias /favicon.ico /var/www/multichat/static/favicon.ico
Alias /media/ /var/www/multichat/media/
Alias /static/ /var/www/multichat/static/
<Directory /var/www/multichat/static>
Require all granted
</Directory>
<Directory /var/www/multichat/media>
Require all granted
</Directory>
WSGIScriptAlias / /var/www/multichat/multichat/wsgi.py
<Directory /var/www/multichat/multichat>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I've installed Redis and have it up and running.
I've included this file in /etc/systemd/system/daphne.service
[Unit]
Description=daphne daemon for multichat
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/var/www/multichat/multichat
ExecStart=/var/www/multichat/env/bin/daphne -b 0.0.0.0 -p 8001 multichat.asgi:application
# Not sure if should use 'on-failure' or 'always'.
Restart=on-failure
[Install]
WantedBy=multi-user.target
Although the webpage comes up and I can login etc, when it comes to a chatroom I have the following error in console:
WebSocket connection to 'ws://multichat.mysite.co.uk/chat/stream/'
failed: Error during WebSocket handshake: Unexpected response code:
404
I'm clearly not setting up something correctly but I don't know where to turn. I would happily scrape Apache if I can get a pointer on how to use just Daphne, but I've tried and got nowhere with that either
You've configured Apache to serve Django content using WSGI protocol, but WSGI doesn't support web sockets. That is why Daphne is here. It doesn't use WSGI to serve Django content, so you can use it with web sockets.
To use Daphne instead, you should remove WSGI settings from apache file and put ProxyPass instead, which should point to your daphne server. The proper line should look like this:
<Location />
ProxyPass http://127.0.0.1:8001/
</Location>
As your daphne server is running on the same server, but on port 8001.
RewriteEngine on
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC,OR]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
RewriteRule .* ws://127.0.0.1:8001%{REQUEST_URI} [P,QSA,L]
<Location />
ProxyPass http://127.0.0.1:8001/
</Location>
#And load the next modules in the main file config:
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_module modules/mod_proxy.so
#remove WSGI settings

Django, Apache2 and Nginx : Long loading time

I use Django as a technology for my website. Let's say that the domain name I use is example.com.
I use Apache2 as my main web server and Nginx to serve static files.
I first installed Apache and tested it. It worked perfectly (Without css and other static files, just the html).
I then installed Nginx (I have never used it before today) and this is where I encountered problems. Indeed when I want to access my website I get the html well as before. But the loading continues and the static files are not recovered.
I do not see any error in the Mozilla terminal.
Here is "Site-available" configuration :
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin contact#example.com
DocumentRoot /var/www/my_site
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
apache.conf :
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
#<Directory /srv/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
# Configuration for Django application
WSGIScriptAlias / /var/www/my_site/site/wsgi.py
WSGIPythonPath /var/www/my_site
<Directory var/www/my_site/my_site>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#
AccessFileName .htaccess
#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
# FQDN
ServerName example.com
My Nginx config :
server {
listen 8000;
server_name localhost;
access_log /var/log/nginx/aa8000.access.log;
error_log /var/log/nginx/aa8000.error.log;
location / {
index index.html index.htm;
}
location ^/static/ {
autoindex on;
root /var/www/my_site/allstatic/;
}
}
And to finish my Django setting for static files :
STATIC_URL = 'http://example.com:8000/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
'/var/www/my_site/static/',
]
STATIC_ROOT = '/var/www/my_site/allstatic'
Nothing in Nginx error log or even in access log.
Edit : Finally I only use apache and it works.
There is what I added in apache conf:
Alias /favicon.ico /var/www/my_site/allstatic/favicon/favicon.ico
Alias /media/ /var/www/my_site/media/
Alias /static/ /var/www/my_site/allstatic/
<Directory /var/www/my_site/allstatic>
Require all granted
</Directory>
<Directory /var/www/my_site/media>
Require all granted
</Directory>
I suggest you add static (and if you need it, media) sections to your apache file like the example at https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/modwsgi/#serving-files in your apache.conf
And are you hosting more than one site? If not, don't use the sites-available; just turn off virtual hosting and don't enable anything in the sites-enabled directory.

Django + Apache + mod_wsgi permission denied

I finished the tutorial on Django's site about using mod_wsgi (here), and having substituted my paths as appropriate, results in a big fat "Permission denied." when I try to access /. Here is the stuff I added to httpd.conf (mod_wsgi is enabled earlier in the conf file):
# Django configuration
WSGIScriptAlias / /usr/local/django/billing/apache/django.wsgi
<Directory /usr/local/django/billing/apache/django.wsgi>
Order allow,deny
Allow from all
</Directory>
AliasMatch ^/([^/]*\.css) /usr/local/wsgi/static/styles/$1
Alias /media/ /usr/local/django/billing/media/
Alias /static/ /usr/local/django/billing/static/
<Directory /usr/local/django/billing/static>
Order deny,allow
Allow from all
</Directory>
<Directory /usr/local/django/billing/media>
Order deny,allow
Allow from all
</Directory>
Edit #1:
I've gone through the slides multiple times, from the start: still no joy. Even after opening up the path to the script, chmod'ing every relevant directory to be readable, and chmod'ing the .wsgi script, I still get permission denied. If I change the directory path from /usr/local/django/billing/apache/django.wsgi to have the django.wsgi truncated, the server returns a configuration error, despite that being how it's configured in the slides.
Same configuration, same environment... but everything was working except a simple call to Popen() in one of my django/python routines...
"Permission denied"
Turned out to be SELINUX (enforcing mode) blocking apache.
You can make SELINUX happy with your application by running the following commands:
# semanage fcontext -a -t httpd_sys_rw_content_t '/path/to/your/app(/.*)?'
# restorecon -R -v /path/to/your/app
I had the same problem with permission denied.
https://serverfault.com/questions/357804/apache2-mod-wsgi-django-named-virtual-servers
The specific error is described in:
http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6#Conference_Presentations
I had the same issue,Sometimes this happends if the WSGI application is located outside of any directories already configured to be accessible to Apache, particularly when it is on your home directory, its good to specify user=username directive.
/etc/apahe2/sites-avaliable/myvhost [section]
WSGIDaemonProcess localhost python-path=/home/hemanth/ecm:/home/env/lib/python2.7/site-packages user=hemanth
WSGIProcessGroup localhost
/etc/apahe2/sites-avaliable/myvhost [full]
<VirtualHost *:80>
ServerAdmin xy#gmail.om
ServerName localhost
ServerAlias localhost
DocumentRoot /home/hemanth/ecm
<Directory /home/hemanth/ecm>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / /home/hemanth/ecm/index.wsgi
WSGIDaemonProcess localhost python-path=/home/hemanth/ecm:/home/env/lib/python2.7/site-packages user=hemanth
WSGIProcessGroup localhost
Alias /static/ /home/hemanth/ecm/static/
Alias /media/ /home/hemanth/ecm/media/
<Directory /home/hemanth/ecm/media/>
Order allow,deny
Allow from all
</Directory>
<Location "/static/">
Options -Indexes
</Location>
ErrorLog /home/hemanth/ecm/error.log
</VirtualHost>
index.wsgi
import os
import sys
import site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/home/hemanth/env/local/lib/python2.7/site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('/home/hemanth/ecm')
sys.path.append('/home/hemanth/ecm/ecm')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ecm.settings")
# Activate your virtual env
activate_env="/home/hemanth/env/bin/activate_this.py"
execfile(activate_env, dict(__file__=activate_env))
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
I got it working after installing flask(in venv) and setting the WSGISocketPrefix.
I am deploying on centos6.8 running python3.6 in venv.
The project folder referenced here is the place where the actual django code is stored. The project public folder references here is accessed by the apache and contains simlinks to relevant resources along with the .htaccess and the .wsgi files relevant for the execution
The socket prefix may vary depending on the os and the apache configuration.
The permissions may vary depending on the apache version if you have issues you can change:
Order allow,deny
Allow from all
to
Require all granted
here is my mod_wsgi configuration (httpd.conf)
LoadModule wsgi_module **path to venv**/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so
WSGIPythonHome **path to venv**
WSGIDaemonProcess flask user=**user name** group=**user group**
WSGIProcessGroup flask
WSGISocketPrefix /var/run/wsgi
<Directory **path-to-project-dir**>
Options ExecCGI MultiViews Indexes
MultiViewsMatch Handlers
AddHandler wsgi-script .py
AddHandler wsgi-script .wsgi
DirectoryIndex index.html index.php index.py app.wsgi
Order allow,deny
Allow from all
</Directory>
here is the virtual host (httpd.conf)
<VirtualHost *:80>
DocumentRoot **project public folder**
ServerName **www.project.com**
ServerAlias **project.com**
WSGIScriptAlias / **project public folder**/site.wsgi
Alias /media/ **project public folder**/media/
<Directory **project public folder**/media>
Order allow,deny
Allow from all
</Directory>
Alias /static/ **project public folder**/static/
<Directory **project public folder**/static>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
here is the site.wsgi file
import os
import sys
import site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('**path to venv**/lib/python3.6/site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('**path to project folder containing manage.py**')
sys.path.append('**path to project folder containing settings.py**')
os.environ['DJANGO_SETTINGS_MODULE'] = '**project name**.settings'
# Activate your virtual env
#activate_venv.py is an empty python file which will activate
#the virtual environment when executed. Create it manually
activate_env=os.path.expanduser("**path to venv**/bin/activate_venv.py")
exec(open(activate_env).read(), dict(__file__=activate_env))
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I had to move following two lines from the wsgi.py to "init.py" in the same folder to solve "Applications not ready error"
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Here is a dump of the packages in the virtual environment
Click==7.0
Django==2.2.1
django-debug-toolbar==1.11
django-redis==4.10.0
django-tastypie==0.14.2
Flask==1.0.2
itsdangerous==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
mod-wsgi==4.6.5
mysqlclient==1.4.2.post1
Pillow==6.0.0
pip==19.1.1
python-dateutil==2.8.0
python-mimeparse==1.6.0
pytz==2019.1
redis==3.2.1
setuptools==41.0.1
simplejson==3.16.0
six==1.12.0
sqlparse==0.3.0
Werkzeug==0.15.4