This article will specifically focus on the deployment of a new Django project. Primarily, this will serve as an initial introduction to some current popular hosting services (AWS, Vercel, and Railway), serving as more of a guide to understanding which platform is right for you and your team before. Once you feel confident on the platform that you wish to deploy on, we will then go into detail on how to successfully deploy your new Django project. After reading this article, you should hopefully have enough knowledge and resources to know which hosting service is best for you (and your team) and start deploying your Django project.
Note: For the sake of consistency, no prior knowledge of DevOps or deployment will be assumed.
- Deployment and DevOps can be a dreadful and daunting task for many. While starting from the beginning it is important to remember, that like any other skill, this will probably take many iterations of past failures before success. Given the vast array of popular hosting services, it is easy to get lost before you can even choose a hosting service. To ease this process, this article collates 3 free-to-use, prominent, and reliable hosting services based on functionality, ease-of-learning, and desirability to learn DevOps: Amazon Web Services (AWS), Vercel, and Railway.
- Each of the 3 hosting services focused on in this article have their own distinct advantages and disadvantages. To compare across these platforms, we will do so in a table format. Note that for the majority of these hosting platforms, you will need a GitHub Account, and a GitHub Repository with your Django Project on it.
It is highly suggested you read through the following table carefully to learn which service you and your team may prefer before continuing:
Criteria | AWS (EC2/EB) | Vercel | Railway |
---|---|---|---|
Complexity (Deployment Difficulty) |
|
|
|
Price of Hosting (Price Charged for Hosting Time) |
|
|
|
Price of Storage (Price Charged for Hosting Storage) |
|
|
|
Security |
|
|
|
Longevity |
|
|
|
Best Features |
|
|
|
Pain Points |
|
|
|
-
Now that you have enough knowledge to know the pros and cons behind each hosting service, it is now time to proceed with one method. This section of the article will help you decide which hosting service is right for you.
-
The following is a list of suggested steps and conversations you should have with both your team and your partner before deciding on which hosting platform to proceed with:
- Discuss with your partner if they would be willing to pay for hosting, especially for security reasons (how much are they willing to pay? Is that enough for a domain to host on AWS over HTTPS? Or can they pay enough to host on Railway provided you are not limited by their storage limit?)
- If you are using Django as a backend framework, discuss with the Frontend team on which web application protocol you will communicate over (HTTP or HTTPS?)
- Discuss the benefits and downfalls of each service with your DevOps/Backend team to come to a consensus on which platform you want to proceed with (are you using SQLite or another database service such as MongoDB? Can you expect the code to grow beyond what Vercel has? Can you expect your SQLite database to go beyond Railway’s storage limits? Are you willing to put in the time and effort to learn Docker and AWS the right way?)
-
AWS itself has two main methods that are the most favourable for beginners to deploy Django projects on. In this part of the article we will discuss the differences between the two to help you decide which one you want to proceed with (should you have decided on moving forward with AWS from the last section).
-
The first key difference to note is the potential for automating your workflow. EB is known to be much more user friendly and serves much more as a personal deployment option rather than a developer’s choice. The main reasoning behind this is due to its inbuilt nature that favours a local repository rather than a group (GitHub) repository with proper workflow capabilities. On the other hand, EC2 itself does much more natively support GitHub repositories, making it a better option (for the general case).
-
The second distinction is in their setup and deployment process. EC2 is much more hands on, and should you want your application to be accessible without your computer constantly having an AWS console open in a browser tab, it will require you to learn NGINX and Docker. Conversely, EB is easier to get started with, as it abstracts away much of the development process that would otherwise be required to set up an EC2 instance (e.g. configurations, load balancers).
-
While both EC2 and EB have their own characteristics, it is important to note that the previously mentioned limitations to AWS applies to both of these.
-
To deploy on EC2, the following video is highly recommended. Note that the following assumptions are made throughout this video and it ensure you meet them before starting the tutorial:
- You have a GitHub repository with your Django project on it
- You have a GitHub Token that authorises the sharing and deploying of that repository, click here for more information on how to set this up
- You have an AWS account, click here for more information on how to set this up
- Install
pip
andvirtualenv
before you begin, click here for more information on how to set this up
-
Additionally, the following are tips that are recommended to encounter as little debugging as possible:
- Make your root directory for the project one level higher than the project files, as seen below:
- When making anything relating to your EC2 instance, ensure you note down the region of the AWS server you are working on (seen in the top right corner of the screen)
- You can generate a
requirements.txt
file after activating your virtual environment by using thepipreqs
package, click here to learn more aboutpipreqs
- If you are encountering CORS/CSRF errors, click here for potential solutions
-
To deploy on EB, the following video is highly recommended. Note that the following assumptions are made throughout this video and it ensure you meet them before starting the tutorial:
- You have an AWS account, click here for more information on how to set this up
- Install
pip
andvirtualenv
before you begin, click here for more information on how to set this up
-
Additionally, the following are tips that are recommended to encounter as little debugging as possible:
- When making anything relating to your EC2 instance, ensure you note down the region of the AWS server you are working on (seen in the top right of the screen)
- After making and activating your virtual environment, ensure you install
gunicorn
by runningpip install gunicorn
within the terminal - You may need to set a third line on your
./ebextenstions/django.config
to the following line:WSGIPath: <project_name>/wsgi.py
- If you are encountering CORS/CSRF errors, click here for potential solutions
-
To deploy on Railway, the following video is highly recommended. Note that the following assumptions are made throughout this video and it ensure you meet them before starting the tutorial:
- You have a GitHub repository with your Django project on it
- You have a GitHub Token that authorises the sharing and deploying of that repository, click here for more information on how to set this up
- Install
pip
andvirtualenv
before you begin, click here for more information on how to set this up
-
Additionally, the following are tips that are recommended to encounter as little debugging as possible:
- Ensure you set your root directory to the Django project in the settings, as shown here:
- Ensure you carefully follow the static files and directory process carefully, this is very important and you should ensure your static files are loading (by checking for common HTML/CSS elements in default Django error/admin panel web pages). This is key and necessary for CORS/CSRF and are vital should you be communicating with a Frontend
- If you are encountering CORS/CSRF errors, click here for potential solutions
-
To deploy on Railway, the following video is highly recommended. Note that the following assumptions are made throughout this video and it ensure you meet them before starting the tutorial:
- You have a GitHub repository with your Django project on it
- You have a GitHub Token that authorises the sharing and deploying of that repository, click here for more information on how to set this up
- Install
pip
andvirtualenv
before you begin, click here for more information on how to set this up
-
Additionally, the following are tips that are recommended to encounter as little debugging as possible:
- If you are encountering CORS/CSRF errors, click here for potential solutions