Deploying Django with Mochahost

April 10, 2017 at 8:04 am / by

Setting up your Django app with Mochahost can be quite an ordeal.  That’s why I’ve put together this little guide to hopefully ease future Mochahost users wanting in on the wonderful world of Django.

Update 2017: I made this post somewhere around the early-to-mid 2000’s, but I still get questions about it so I just decided to move it to my updated blog.

First thing you’ll probably need to know is that, no, there is no shell access.  At least for Business account users.  Second, Mochahost provides a one-page tutorial on How to deploy a Django web application.  And if it worked exactly as you’d expect, then you wouldn’t be reading this guide.

The good thing about their Django deployment tutorial is that it does give a decent starting point.  It is somewhat outdated though, as Django and mod_python are already setup for you, so you don’t need to create a ticket to get them going.

If you’ve followed the mochahost tutorial by installing your project files in ‘webapps’ you’re ok so far.  The main point of contention is the .htaccess file.

Mochahost suggests your .htaccess code looks like this:

But, the problem is that this won’t work.

What’s missing here are details from the official Django documentation site, here How to use Django with Apache and mod_python. See?


Mochahost doesn’t use directives like ‘Location’or ‘Directory’, in fact if you try using them you’ll see in the error logs that it’s not allowed.

So, what to do?
Follow the directions in the Djangoproject.com page, but without directives:


SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myproject.settings
SetEnv PYTHON_EGG_CACHE /home/useraccount/.python-eggs
PythonDebug Off
PythonOption django.root /home/useraccount/webapps
PythonPath "['/home/useraccount/webapps/django', '/home/useraccount/webapps'] + sys.path"

You’ve probably noticed that there are a few extra bits and lines.  The details are in the Django documentation pages, but interestingly, I don’t remember adding the setENV line about the egg, I believe Mochahost tech support added that.  Maybe they’re not so bad after all?

Stick that bit into your .htaccess, comment out whatever mochahost already put in there, and see her run!

 
 

Comments are closed.