Create a django project "mysite"
In "mysite" project we're going to change it a bit and add an apache directory which contain three files:
In "mysite" add apache folder structure
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
apache/
__init__.py
override.py
wsgi.py
myapp/
models.py
views.py
The empty __init__.py file tells Python to treat the directory as a package.
Add following content in override.py
# override.py
from mysite.settings import *
DEBUG = True
ALLOWED_HOSTS = ['www.mydomain.com', 'mydomain.com']
Add following content in wsgi.py
#wsgi.py
import os, sys
# Calculate the path based on the location of the WSGI script.
apache_configuration= os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
sys.path.append(project)
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.apache.override'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Change ownership of apache folder
sudo chown www-data:www-data apache/
Configure Apache Settings
----------------------------------
Add static and wsgi path in 000-default.conf
sudo nano /etc/apache2/sites-enabled/000-default.conf
Alias /static /home/pranav/Django/projects/mysite2/static
<Directory /home/pranav/Django/projects/mysite2/static>
Require all granted
</Directory>
<Directory /home/pranav/Django/projects/mysite2/mysite2/apache>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/pranav/Django/projects/mysite2/mysite2/apache/wsgi.py
Finally, save and close the file and restart Apache to see the changes:
sudo service apache2 restart
Courtsy : https://www.sitepoint.com/
Comments
Post a Comment