Sign In
Sign In

Deploy a Django App

Updated on 14 May 2024

To deploy a Django application on Hostman, go to the App platform section and click Create.

Step 1. Select the application type

Go to the Backend tab and select Python Django.

The App Platform uses Python 3.8.

590f358c 70ff 468a Bcba 4b3cf49ddd8b

Step 2. Connect a repository

You can connect a repository:

  • From your GitHub, GitLab, or BitBucket account. Click on the platform name, log in and select the desired repository. If you are already logged in, Hostman will immediately show the available repositories.

  • By URL, providing a link to a repository created on any platform. Click Connect the repository via URL and enter the Git URL of the repository. If the repository is private, also enter the access details.

Read more about connecting repositories here.

Step 3. Select a branch and commit

  1. Select a branch for deployment.
  2. By default, we enable the Build by the last executed commit option. In this case, the App platform will deploy the latest commit, and later will automatically rebuild the application when you add new commits to the repository. If necessary, you can disable automatic deployment in the future.

If you want to select a specific commit manually, disable this option.

Step 4. Select server location and configuration

Your Django application must run on a separate cloud server. Select the region where the server should be located and its configuration.

You can always upgrade your server later, however, downgrading will not be possible.

Step 5: Configure the build settings

The App Platform will automatically determine the build and start commands for your project, so in most cases you can leave these parameters unchanged. We will also install the dependencies defined in the requirements.txt file, if it exists. The App Platform uses Python 3.8.

If your project requires additional modules, you can specify your own build command or several, combining them using &&. For example, if you need to install specific drivers, add to the build command:

apt install <package name>

You can also set variables if required.

The start command will be:

python3 manage.py runserver 0.0.0.0:8000

Make sure that the project initialization file is named manage.py.

You will be able to change any of these settings later and redeploy the app with the new parameters.

Step 6: Enter the app information

Here you can specify a name and a comment for your application to be displayed in the Hostman dashboard. You can also select a project to add the app to.

These settings can also be changed later.

Step 7. Deploy

Click Start Deploy. Once the process starts, you will see the deployment log on the Deploy tab.

The deploy log contains all the necessary information to solve possible issues. If something goes wrong, for example, due to errors in the code, the deploy log will display the notification about it specifying the cause of the problem.

When you first deploy a project, the server installation may take some time. Once the process is completed, the application status will be updated, and you will also see a message about this in the log.

All done!

You can find the application's IP address and the technical domain linked to the app in the Dashboard tab. The application will be available on port 443; port 80 is also open.

To link your own domain to the app, follow this guide.

In the future, the App platform will monitor updates in the repository and, if automatic deployment is enabled, automatically rebuild the project with new changes.

Troubleshooting

Deployment fails

If there are problems with deployment, first check the deployment log. You will be able to determine at what point something went wrong.

Often the problems are related to the start command. Check that everything in your development environment works with gunicorn. Make sure that all modules required to run the application are present in the requirements.txt file.

DisallowedHost at /Invalid HTTP_HOST

The problem occurs when the hostname is not specified in the settings.py file.

This setting is a security measure to prevent HTTP Host header attacks.

To fix the problem, you need to make changes to the settings.py file, specifying your domain in the ALLOWED_HOSTS directive, for example:

ALLOWED_HOSTS = ["your.domain.com"]

You can also allow all domains if you don't want to use this security measure:

ALLOWED_HOSTS = ["*"]
Was this page helpful?
Updated on 14 May 2024

Do you have questions,
comments, or concerns?

Our professionals are available to assist you at any moment,
whether you need help or are just unsure of where to start.
Email us
Hostman's Support