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".
|Server||Path||Django Version||Python Version||Loader|
- 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.
- Our Python installation includes the MySQL extension for interfacing with the MySQL database engine.
- Our Python installation includes the PostgreSQL extension for interfacing with the PostgreSQL database engine.
- Our Python installation includes the SQLite extension for interfacing with the SQLite database engine.
- Extensive prebuilt libraries
- If you need any additional libraries installed be sure to ask at http://helionet.org/
- 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.
Getting Started with Django < 1.10
Django 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.
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 paths below to match your account details!
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 project_subdirectory below to your subdirectory name!
RewriteEngine On RewriteBase / RewriteRule ^(media/.*)$ - [L] RewriteRule ^(admin_media/.*)$ - [L] RewriteRule ^(dispatch\.wsgi/.*)$ - [L] RewriteRule ^(.*)$ project_subdirectory/dispatch.wsgi/$1 [QSA,PT,L]
Getting started with Django 1.10
The official Django 1.10 documentation is available here.
It's suggested to follow the introduction tutorial to start off with Django: another suggestion is to try and test the package locally before uploading it online, since shell access (sometimes useful for debugging) is not provided on heliohost.
Django 1.10 (available on Tommy) comes with a new structure to manage its web-apps, so we're going to look in details how to set it up on a shared hosting like heliohost. This small tutorial has been thought for linux users, but Windows users should work it out easily.
Let's start by creating an empty "dumb" application to play with: refer to the official documentation for instructions on how to setup django on a personal computer (we suggest using virtualenv, to differentiate each django installation for each project).
Conventions: all the following commands don't need root access to be executed, but the shell commands are preceded by a $ (dollar sign) to differentiate them from the output.
The python executable name used on the local computer is python3 (as on a Fedora OS), but this could change according with the distribution used (e.g. Ubuntu could name it python3.6): change it accordingly to your executable name.
On your local computer, open a terminal, create a new project and perform the minimal configuration:
$ django-admin startproject hello $ cd hello/ && python3 manage.py migrate
This should return a directory structure like this:
$ tree ../hello/ ../hello/ ├── db.sqlite3 ├── hello/ │ ├── __init__.py │ ├── __pycache__/ │ │ ├── ... │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── manage.py 2 directories, 10 files
Run the included testing server:
$ python3 manage.py runserver 0.0.0.0:8000 Performing system checks... System check identified no issues (0 silenced). March 20, 2017 - 16:42:48 Django version 1.10.6, using settings 'hello.settings' Starting development server at http://0.0.0.0:8000/ Quit the server with CONTROL-C. ...
Now you can point your browser to the address stated ( http://127.0.0.1:8000 ), and you should see the django "hello world" debug message.
Let's set the project up to work on heliohost; we need to rename and link back the wsgi.py file.
$ cd hello/ $ mv wsgi.py dispatch.wsgi
(Windows users should skip the following step and manually copy dispatch.wsgi to wsgi.py each time they overwrite dispatch.wsgi):
$ ln -s dispatch.wsgi wsgi.py
In this way, you can go on doing any edit you need on wsgi.py, since it's just a symbolic link to dispatch.wsgi, which is a configuration file needed to make your django webapp work on heliohost.
Then create a .htaccess file containing the instructions for the Apache web server to redirect http requests to your django app. The content should be:
RewriteEngine On RewriteBase / RewriteRule ^(media/.*)$ - [L] RewriteRule ^(admin_media/.*)$ - [L] RewriteRule ^(hello/dispatch\.wsgi/.*)$ - [L] RewriteRule ^(.*)$ hello/dispatch.wsgi/$1 [QSA,PT,L]
This instructs Apache to redirect all the requests (except those requesting something from media/ or admin_media/) to the dispatcher file.
We are not done yet: we need to tell the dispatcher file dispatch.wsgi how to load your django settings; change it from:
import os from django.core.wsgi import get_wsgi_application os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hello.settings") application = get_wsgi_application()
to something like:
import os, sys # edit your username below sys.path.append("/home/username_on_heliohost/public_html") from django.core.wsgi import get_wsgi_application os.environ['DJANGO_SETTINGS_MODULE'] = 'hello.settings' application = get_wsgi_application()
Change username_on_heliohost to the heliohost username used on the webserver.
In order to allow the webserver to serve your django app, you need to add the webserver address in the app settings. Change hello/settings.py and change:
ALLOWED_HOSTS = 
ALLOWED_HOSTS = ["*"]
so your website (say djangoprogrammer.heliohost.org, every custom domain you set up like djangoprogrammer.com and every subdomain such as www.) can be served by your application.
Now upload the content of the hello/ folder to your public_html/ folder, using whichever method you prefer, so the final content on the heliohost web server should be something like:
$ tree home/ home/ └── username_on_heliohost/ └── public_html/ ├── db.sqlite3 ├── hello/ │ ├── dispatch.wsgi │ ├── __init__.py │ ├── __pycache__/ │ │ ├── ... │ ├── settings.py │ ├── urls.py │ └── wsgi.py -> dispatch.wsgi └── manage.py 4 directories, 10 files
Eventually you can point your browser to your website address(es) and you should see your django application being online!
- The original discussion from which the tutorial for django 1.10 came out: http://www.helionet.org/index/topic/27585-django-on-tommy/