Python & Django
Python is a relatively new programming language that offers multiple programming paradigms packaged in a unique syntactical approach. By integrating standard procedural paradigm with an enhanced object-oriented approach, Python is able to provide an easy learning curve in combination with many advanced features missing from similar languages. And by reenvisioning syntax for language features such as code blocks, Python is able to further enhance code readability.
Django is a web development framework designed specifically for Python. Like Ruby on Rails does for Ruby, Django aims to provide a Model-View-Controller framework for web application development as well as a large set of prebuilt libraries to simplify development of common webapp features. Django's modularity also allows easy scalability and enables the reuse of various code blocks, under the policy of "Don't Repeat Yourself".
|

|
| |
Details
Libraries, extensions, and configuration options
ENABLED:
- WSGI
Using the WSGI loader for a shared hosting environment is ideal because it conserves memory and enhances security.
- Complete Django
We offer the complete, unadulterated Django package. For more information and for specific libraries, check the Snake Charmer link above.
- MySQL
Our Python installation includes the MySQL extension for interfacing with the MySQL database engine.
- PostgreSQL
Our Python installation includes the PostgreSQL extension for interfacing with the PostgreSQL database engine.
Need shell? Try Bluehost.
- SQLite
Our Python installation includes the SQLite extension for interfacing with the SQLite database engine.
- Extensive prebuilt libraries
For a complete list, check the Snake Charmer link above.
DISABLED:
- Shell access
We don't offer shell (command line) access to our users. Many Django tutorials and installation instructions assume that users have command line access, which may make working with Python & Django more difficult. Most people tend to develop on their home computer and then upload to their web server, which almost negates the need for this feature. Furthermore, most configuration done through the command line can be done through other methods, such as FTP and manual file editing.
- WSGI daemon mode
There are two ways to configure Django to work with the mod_wsgi loader in Apache. You can either create a separate daemon for each Django process (daemon mode), or embed Django into the Apache daemon (embedded mode). While daemon mode tends to be the standard among Django admins because of the increased control it offers, we use embedded mode because it can be setup on a per-user basis without very much root-level configuration. Embedded mode is slightly harder to get working (see directions below), and might break compatibility with some Django tutorials. In most cases it should not be a problem.
How do I use Python/Django?
We recommend The Python Tutorial for learning Python, and the Django Book for learning Django.
Python scripts are easy to configure and run. Just create a file in your cgi-bin directory under public_html, and place the Python "shebang" line (#!/usr/bin/python) on the first line of the file. Below this line you may write Python code. Make sure you make this file's CHMOD permissions 755, and output a Content-type header before anything else.
|
|
Django, on the other hand, is probably the hardest scripting feature to configure on HelioHost. If you have not yet created a Django application, we suggest that you develop at home and upload to HelioHost after you are finished. This is because the use of the command-line utility django-admin.py is common during the development process, and HelioHost does not allow command-line access to its users. Development can be done without this utility, however. If it is your wish to develop on-site you will need to manually create a blank __init__.py file, a settings.py file, and a urls.py file. To learn more about these files try the learning links provided above.
Follow the steps below to get a Django application working on HelioHost:
- Create a new subdirectory of the public_html directory in your account root. Name this subdirectory the same name as your Django project. Now, upload your Django project to the specified subdirectory through either FTP or the cPanel File Manager.
- Next, we need to create a temporary cache for Python to store its modules, also known as eggs. Create a directory in your home directory (ie. /home/your_cpanel_username) called ".python_egg_cache". Make sure to set this directory's permissions to 777!
- Next, we have to create a dispatch file to handle your project. Django WSGI embedded mode requires some directives to be cast before execution of the main project, and thus a dispatch file must be wrapped around your project. Copy the file below into the aforementioned project subdirectory, naming it "dispatch.wsgi". Make its CHMOD permissions 755. Remember to change the highlighted text below to the correct paths!
Expand to view dispatch.wsgi file contentsExpand
import os, sys
sys.path.append("/home/your_cpanel_username/public_html/project_subdirectory");
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
os.environ['PYTHON_EGG_CACHE'] = '/home/your_cpanel_username/.python_egg_cache'
import django.core.handlers.wsgi
_application = django.core.handlers.wsgi.WSGIHandler()
def application(environ, start_response):
environ['PATH_INFO'] = environ['SCRIPT_NAME'] + environ['PATH_INFO']
return _application(environ, start_response)
- The final step is to redirect all requests for the project subdirectory to the dispatch file we just created. For this, we will use mod_rewrite directives in an .htaccess file. Copy the file below into the aforementioned project subdirectory, naming it ".htaccess". Make its CHMOD permissions 644. Remember to change the highlighted text below to your subdirectory name!
Expand to view .htaccess file contentsExpand
RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(admin_media/.*)$ - [L]
RewriteRule ^(dispatch\.wsgi/.*)$ - [L]
RewriteRule ^(.*)$ project_subdirectory/dispatch.wsgi/$1 [QSA,PT,L]
|
|
|