put python+django to apache through virtualhost

to put python+django to apache through virtualhost

1) edit /etc/httpd/conf/httpd.conf

Listen 83

<VirtualHost *:83>
        WSGIScriptAlias / /root/workspace/MyDjangoProject/P1/wsgi.py
        AddType text/html .py
        <Directory /root/workspace/MyDjangoProject>
                AllowOverride None
                Options +ExecCGI +Indexes
                Order allow,deny
                Allow from all
                Require all granted
        </Directory>
</VirtualHost>

2) edit /root/workspace/MyDjangoProject/P1/wsgi.py, change it to

from django.core.wsgi import get_wsgi_application
import os
import sys

path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if path not in sys.path:
    sys.path.append(path)

path = '/usr/share/myapplication'
if path not in sys.path:
    sys.path.append(path)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "P1.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.
application = get_wsgi_application()

Leave a Reply

Your email address will not be published. Required fields are marked *