Flutter signup/login application with Django backend #2
django tutorial django-rest-framework login heroku

April 19, 2020, 12:44 a.m.

Flutter signup/login application with Django backend #2

  166

Next steps

This post is in continuation of the other post that written on the same topic. If you have not read that, please go ahead and give it a read so that you can follow along with this one. Flutter signup/login application with Django backend #1.

Host your application

Since this series of posts will be a detailed step by step procedure that can be replicated to get the exact same application running, I thought it would be a good idea to include this step in the process. When it comes to hosting Django application you have two options:

1. Host it on a VPS (you need to configure gunicorn and Nginx for it refer: this tutorial).
2. Host it on Heroku (or python anywhere etc. etc).

Well, to be honest, the second method is relatively simple and we are going to do just that as our aim here is to just see how stuff works.

Hosting your application on Heroku

Changes required

Heroku provides a very easy method for hosting Django applications, the first step is to modify a few settings and add a few files in order to prepare our application for hosting.

We will be deploying using gunicorn so let us install that, run:

pip install gunicorn

We will be using django-heroku package to configure our setting.py file automatically. Thus, install that too:

pip install django-heroku

The first file we need to include is requirements.txt so that Heroku can recognize your application as a python application. Thus, activate your virtual environment and run:

pip freeze > requirements.txt

from HOME/

Create a Procfile

nano Procfile

and add :

web: gunicorn HOME.wsgi --log-file -

For the admin portal to run properly, we need static files' support, for that, we need to configure STATIC_ROOT property in our settings.py file, we also need to include django-heroku settings in the file. Thus, modify your HOME/HOME/settings.py and add the following:

import django_heroku # add in the beginning

... # denotes rest of the code in between

# add these lines at end
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

django_heroku.settings(locals())

Pushing our code to deploy it

We need to create an account on heroku and install heroku-cli. These instructions suffice for Ubuntu / Windows / Mac. For manjaro linux users, you could use:

yay -S heroku-cli

It is the perfect time to log in to your heroku cli, run

heroku login

Next, we need to create an app, run

heroku create <app_name>

Now copy all your files from the HOME/ directory to this app_name/ directory we created just now.

Now is the time to run these magic commands (we are deploying using git make sure git bash is installed refer: here)

git add .
git commit -m "deploying to heroku"
git push heroku master

Now we need to migrate our changes on the heroku server as well. Thus run:

heroku run python manage.py migrate

Also, create a superuser with the same credentials as your local application (for consistency).

heroku run python manage.py createsuperuser

You should now be able to call your APIs with the URL you got here. Verify the functionality using POSTMAN before proceeding. Also, refer to the previous post for details about the endpoints, etc.

Next Post: Flutter signup/login application with Django backend #3

Previous Post: Flutter signup/login application with Django backend #1

Share this article:

Comments

Leave a comment

Related articles

Flutter signup/login application with Django backend #1

Flutter signup/login application with Django backend #1

Introduction This series of posts intends to develop a flutter signup/login app working with API calls to Django backend. The …

Read Story
Flutter signup/login application with Django backend #3

Flutter signup/login application with Django backend #3

What this post is about In the previous two posts, we made an API in Django with the help of …

Read Story
Converting any HTML template into a Django template

Converting any HTML template into a Django template

Djangify A Python script developed by Ohuru that converts HTML Files / Templates to Django compatible HTML Templates. This post …

Read Story

Stay right up to date

Get great content to your inbox every week. No spam.
Only great content, we don’t share your email with third parties.