USING RAILWAY APP TO DEPLOY YOUR DJANGO PROJECT
Tags: django, python, github
Published: 2022-07-03 00:33:11


Alright guys, at the end of this article I hope you should be able to deploy your first Django project on Railway app.

Railway app is a cloud platform that gives you simple configured free deploys, removing common developer hurdles with zero CLI, just to add as a bragging rights it has a faster build time than Heroku, interestingly I discovered it while I was having issues deploying my project to Heroku check [here](https://dev.to/osahenru/the-new-trick-to-easily-and-effectively-deploy-your-django-project-on-heroku-in-just-10-steps-7i) to see how I did that.

All you need to get started is your GitHub repo. Railway has some starter applications which can be deployed on the go, and it also comes with a PostgreSQL as the default database manager.

In this article an explanation to some of the terminologies used here are not given, it is assumed that the reader must be familiar with them if not check out this [article](https://dev.to/osahenru/the-new-trick-to-easily-and-effectively-deploy-your-django-project-on-heroku-in-just-10-steps-7i) where I explain these terminologies in details.

With that much said let us dive in, using these steps i'll show you how to deploy your Django projects on railway.

Ensure you already have a Railway account if don't you can sign-up [here](https://railway.app/), A GitHub account and the project you want to deploy is been cloned once you’re done these 3 basic things follow these steps.

**Step 1.**
`pip install gunicorn`

**Step 2.**
`pip freeze > requirements`

**Step 3.**
Create a `Procfile` in your root folder and save the following lines of codes in it
`web: gunicorn 'name-of-application.wsgi'`
_Note: A Procfile has no file extension_

**Step 4.**
Create `runtime.txt`
_Railway needs to know the version of python you used for your project, to know the version used type_ `python --version` _in your terminal copy, paste and save the version inside your_ `runtime.txt` `python -3.10.2`

**Step 5.**
Next, we need to make some adjustments to our `settings.py` file
Look for the line that has

`ALLOWED_HOST = [ ]`

and change it to

`ALLOWED_HOST = ['*']`

**Step 6.**
Still on your `settings.py` file add the following lines of codes in your static section, so your static files can be properly rendered

`STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATIC_ROOT =os.path.join(BASE_DIR, 'staticfiles')`

**Step 10.**
Lastly, we collect our static files into one folder using the following command
`python manage.py collectstatic`

Next, we push our project to our Github account where we’ll be deploying our project from. Use the following git syntax to add, commit and push your code.
`git status
git add .
git commit -m ‘customized commit message’
git push`



Now, we move to our railway app account that was created

Click `+ New `

![How to add new project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c4hxlxfbd4t0au9stybr.png)

`GitHub Repo` 

![Select your GitHub repo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2w7t52w6yloip0a4j6r9.png)

select a repo and Railway pack helps you build and automatically deploy your project using nixpacks you can see the build status as it is been built, once that has been done, 

![Build status](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4zsf5nl2fmvx7n44m9e8.png)

click on your project go to the `settings` tab 

![Settings tab](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ieqxmr8pwouyida3haw.png)

under domain click generate domain

![Generate domain](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f185bcr1m7y46w2eaum5.png)

a customized link to your deployed app is been created you can visit it by clicking on it.

![View generated domain](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9sq8ery6gv8ny1xugdcf.png)

VOILA!!!
Your project has been deployed.
CONGRATULATIONS!!!