Converting an Existing Django App
Last updated
Last updated
Django is a web development framework designed specifically for Python. As Ruby on Rails does for Ruby, Django aims to provide an MVC (Model-View-Controller) architecture for web application development as well as a large set of prebuilt libraries to simplify the development of common web app features. Django's modularity also allows easy scalability and enables the reuse of various code blocks, aligning to the DRY ("Don't Repeat Yourself") software development principle.
If you need to run Django on another version of Python, you'll need to get a VPS.
Server | Django Version | Python Version | Python Modules Installed | Python Path | Loader |
---|---|---|---|---|---|
If you need to run Django on another version of Python, you'll need to get a VPS.
Server | Django Version | Python Version | Python Modules Installed | Python Path | Loader |
---|---|---|---|---|---|
Using the WSGI loader for a shared hosting environment is ideal because it conserves memory and enhances security.
Django changes can take up to 2 hours to appear consistently on your site because WSGI uses server side caching.
If you want site changes to take effect immediately, we offer a few options to work around caching.
We offer the complete, unadulterated Django package, including extensions to interface with MySQL, PostgreSQL, and SQLite database engines.
View the Python modules installed on Johnny. View the Python modules installed on Tommy.
To request additional libraries, please raise a request in the Customer Service forum, making sure to provide your username, your server, and the libraries you need including any relevant version numbers for them.
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.
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 set up 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.
This tutorial will guide you through using the command line on your development system to convert an existing Django app for hosting on HelioHost.
If you prefer not to use the command line, our brief Django on HelioHost tutorial may better suit your needs.
We recommend referring to the official Django documentation and following the introduction tutorial relevant to the Django version you are using. Please note the Django versions available are different on the Johnny and Tommy servers. We also suggest using virtualenv
to differentiate each Django installation for each project. The below tutorial has been designed for Linux users, but Windows users should work it out easily.
Conventions: The following commands don't need root access to be executed. 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
, but this can vary depending on the distribution used, so change it as needed to match your system requirements.
djangotest
On your local computer, open a terminal, create a new project and perform the minimal configuration:
The below directory structure, with a djangotest
folder nested inside another djangotest
folder, is standard for a Django project. Please note that you cannot name the project folder django
, it will not work. This is why the name djangotest
has been used for this tutorial.
Make sure that your directory structure and files look like this:
Inside the first (outer) djangotest
folder, start the testing server.
By using the test server, you can develop the app on your local computer and changes you make will take effect immediately.
Point your web browser to http://127.0.0.1:8000 and you should see a message confirming the installation worked successfully:
Django changes can take up to 2 hours to appear consistently on your site because WSGI uses server side caching.
If you want site changes to take effect immediately, we offer a few options to work around caching.
wsgi.py
file to dispatch.wsgi
To prepare the project for deployment, rename the wsgi.py
file to dispatch.wsgi
. Both files are inside the second (inner) djangotest
folder.
.htaccess
fileInside the first (outer) djangotest
folder, create an .htaccess
file with these contents:
This instructs Apache to redirect all the requests (except those requesting something from media/
or admin_media/
) to the dispatcher file.
dispatch.wsgi
fileInside the second (inner) djangotest
folder, edit the dispatcher file dispatch.wsgi
to instruct it how to load your Django settings. Change it from:
To the below:
If you were transferred from the old cPanel, your main domain will be parked on the public_html
directory.
If you created a new account on Plesk, your directory will be httpdocs
.
urls.py
fileInside the second (inner) djangotest
folder, edit the urls.py
file. Change it from:
To the below:
Commenting out the path to the admin interface is done for security reasons, to prevent unauthorized access to the admin panel in a production environment.
settings.py
fileInside the second (inner) djangotest
folder, edit the settings.py
file.
Adding the web server address to the app settings will allow the web server to serve your Django app. Change it from:
To the below:
This will ensure that your website (such as domain.heliohost.us
) can serve your application from any custom domains you have (such as domain.com
) as well as every subdomain (such as www
).
Upload the entire first (outer) djangotest
folder to your main domain. Make sure that your directory structure and files look like this:
Django changes can take up to 2 hours to appear consistently on your site because WSGI uses server side caching.
If you want site changes to take effect immediately, we offer a few options to work around caching.
In your web browser, navigate to domain.helioho.st/djangotest
If you did everything right it should look like this:
Multiple Apache processes are running on the server, and each time you refresh your site you are randomly assigned to one of these processes. If that particular process has already displayed your site, it shows the cached version of your code; otherwise, it shows the new code changes. This means that during the first 2 hours after a site change, you may intermittently see old or new content, depending on which process you get assigned to. This situation will resolve when Apache is restarted, which happens every 2 hours.
A new feature currently in beta is the ability for users to restart their Django app themselves.
To request this, please create a new post in the Customer Service forum and provide your username, server name, and the domain name(s) you want to be given WSGI Control Access for. (If you have 2 Django apps on 2 different domains, you need to request WSGI Control Access for each domain.)
Once you have been given WSGI Control Access, you can edit your dispatch.wsgi
to reload your Django app so new code changes load immediately. The edits to the file can be as simple as adding or removing a space or a blank line. As long as the file's last modified date
changes it will discard the cache and reload your Django app.
Please let us know if you experience unexpected results with this new feature.
If you request an account reset you will need to re-request WSGI Control Access after the reset has been completed. By default, account resets will disable WSGI Control Access.
Another option to see code changes reflected immediately is to develop your Django app on your home computer and then host the production copy on the server.
You may prefer to explore one of our paid VPS Plan options, depending on your requirements.
This tutorial is adapted from this post on the HelioNet forum.
A ready-made template using an older Django version (1.11) is available at https://github.com/rahul-gj/cookiecutter-helio.
Johnny
5.0.7
3.12
/usr/bin/python3.12
WSGI
Tommy
5.0.7
3.12
/usr/bin/python3.12
WSGI