You can run different types of applications on Python using Hostman: APIs, background workers, cron jobs, private services, and others.
Hostman provides CI/CD for all types of services as well as great scalability.
To deploy a Django application, follow these steps.
Step 1. Create a service
Click Create in the top-left corner of your Dashboard and choose Back-end app.
Step 2. Select the project to deploy
If you are logged in to Hostman with your GitHub, GitLab or Bitbucket account, at this point you will see the repository with your projects, including the private ones.
Choose the project you want to deploy. It must contain the manage.py file and the directory with the project’s files.
If you need to access a different repository, click Connect another repository.
If you didn’t use your Git account credentials to log in, you’ll be able to access the necessary account now, and then select the project.
Step 3. Choose a server
Your Django application must run on a specific cloud server. Choose the location and configuration of this server. You can upgrade it in the future.
Step 4. Configure the build settings
Next, the App customization window will appear.
First select Python environment and then Django from the list of frameworks.
Then make sure to fill in the Start command correctly.
We use gunicorn to launch Python applications, as it is a reliable, fast and scalable WSGI server.
Django creates a wsgi.py file inside your project directory, so the correct format for a start command will be:
If necessary, also fill in the Build command. It allows you to customize the build process. You can enter multiple commands separated by &&.
Step 5. Deploy
Click Deploy to start the build process.
Once it starts, you will enter the deployment log. If there are any issues with the code, you will get warning or error messages in the log, specifying the cause of the problem. The log contains all the debugging data you'll need, but we are also here to help you solve the issues, so do not hesitate to contact us via chat.
Usually it takes some time to install the cloud server during the first deployment.
When the deployment is complete, you will receive an e-mail notification and also see a similar log entry:
Your project is up and ready.
The deployment fails
If the deployment fails, first of all check the deployment log. You'll see the stage where something went wrong.
The most common issues are with the start command. Check that everything is working with gunicorn in your development environment. Check that all the modules your need to launch an application are in the requirements.txt file.
DisallowedHost at /Invalid HTTP_HOST
This issue is caused by Django when you didn't set up the host name in settings.py file. It's a security measure to prevent HTTP Host header attacks.
What you want to do is to update settings.py file, changing ALLOWED_HOSTS to something like this:
ALLOWED_HOSTS = ["your.domain.com"]
Or you can allow all domains this way if you don't want to use this security measure:
ALLOWED_HOSTS = ["*"]