This article will show you how to run an automatic installation script to set up Django in a Python virtual environment within a WebApps project.

If you do not have a WebApps section in your hosting Control Panel, then this tutorial is not suitable for your particular hosting environment. You can submit a support ticket through our ticketing system if you need assistance.

We will set up a Django production environment. We will use Python 3, pip 3, Django 5, Python's MySQL client (mysqlclient), and uWSGI in order to provide you with the tools necessary for running web applications with Django.

Prerequisites:

  • Enable SSH Access to your account.
  • Enable the Compiling tools option for your account.

Both of these actions can be performed through the SSH Access section of the hosting account's Control Panel. 

1. Create a directory for Django

To start, you first need to create a directory for your Django project. You can create the directory using the File Manager in your hosting Control Panel. This directory needs to be created under the /private directory on your account. In this example, we will create a subdirectory called "django". 

2. Create a MySQL 8 database for Django

To use MySQL with your Django application, you need to create a new MySQL 8 database and user via the MySQL Databases > MySQL 8 section in your hosting Control Panel. The installation script will later prompt you to enter the MySQL 8 database name, username, and password. 

3. Create a web app for Django

Next, you need to create an app for your Django project. Running Django as a web app allows the application supervisor on the server to manage the application. You can create an app for Django using the WebApps section of the hosting Control Panel as follows:

  • Enter a name for your app. It is only for internal reference to the app. In this example, it is Django.
  • Choose Custom as Engine.
  • Choose a domain and subdomain at which you wish to access the app. In this example, we choose www.mydomain.com.
  • Enter the web access path. For example, if you enter /django, you will be able to access the app at https://www.mydomain.com/django. You do not need to create the directory. In this example, we enter / (forward slash) as web access path, so the app is accessible at https://www.mydomain.com.
  • Select the deployment directory. This is the directory you created in step 1 (/private/django).
  • Leave the Start command field empty.

 Django WebApp Create

4. Install Django

It is now time to run the automatic installation script. To do so, follow these steps:

  • Click on the Linux shell icon under Actions next to your app.
    Open Project Shell
  • In the project shell, run the following command:

bash <(GET https://tickets.suresupport.com/faq_img/7919.sh)

  • The script will start by setting up a Python virtual environment and installing the required packages. Then, it will prompt for the MySQL settings. Use the MySQL 8 database and user created in step 2.
  • Once the MySQL 8 database is set up, the script will create a Django superuser. You need to enter username, email address, and password.
  • Finally, the script will configure the uWSGI application server and will start Django. You can now open the URL of the Django installation. The following page should show up:

 Django 5 home page

5. Admin interface

The installation script generates a default project template. The Admin interface is accessible at /admin (e.g. https://www.mydomain.com/admin).

6. Debug Mode

The default Django settings.py file is created with "DEBUG = True" for convenience. For a production environment, the DEBUG mode should be disabled. To do so, you need to edit the ~/private/django/myproject/myproject/settings.py file. Find the following line:

DEBUG = True

and change it to:

DEBUG = False

Then, stop the app and start it again. Note that if you have not created a home page, a "Not Found" error will show up when you open the URL of the Django installation.