skip to primary navigationskip to content
 

Python

Python support

Python v2.7 is installed in MWS sites and the Apache module mod_wsgi is installed by default. This allows you to host a python website using a Python-based framework such as Django, Flask, etc.

You will need to configure your .htaccess properly in order to make your python-based website work.

MWS support for Django

  • Copy your Django project inside the docroot directory within your website space in your MWS site. This is usually /var/www/[site name]/docroot,  where [site name] will be the name of the website you have set up in the MWS web control panel.
  • Create a .htaccess file in /var/www/[site name]/docroot/ and add the following:
AddHandler wsgi-script .py
Options FollowSymlinks ExecCGI MultiViews Indexes
MultiviewsMatch Handlers
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ django_project/django_app/wsgi.py/$1 [QSA,PT,L]
  • add to django_project/django_app/wsgi.py the following:
import sys
sys.path.append('/var/www/default/docroot/django_project')

You can also add your own virtualenv to the django_project/django_app/wsgi.py file using sys.path.append and adding your virtualenv packages directory: venvdir/lib/python2.7/site-packages

Be sure to give correct permissions to your virtualenv folder.