Deploy MovieDB Application
Download these tools and install it on your computer(Prerequisites)
🚀The Heroku CLI | Heroku Dev Center
🚀Git — Downloads (git-scm.com)
Create Account on Heroku
Back To Pycharm(Execute the below codes on pycharm)
pip freeze > requirements.txt
At the end of ‘vidly/settings.py’ add the following statement.
STATIC_ROOT = os.path.join(BASE_DIR, ‘static’)
Create a New File in Root
Name it Excatly as this -> “Procfile” , because heroku looks for it when deploying;
And make sure you give the project name before “”.wsgi;
#If you followed the tutorial code then copy and paste this
web: gunicorn vidly.wsgi
Now, you are required to install Gunicorn and Django Heroku.
pip install gunicorn
pip install django-heroku
freeze again :
pip freeze > requirements.txt
Now, you need to import ‘django-heroku’ right after import os in vidly/settings.py
import django_heroku
Now, to activate ‘django_heroku’ you are required to go to the end of ‘settings.py’ and add in the following lines of code.
# Activate Django-Heroku.
django_heroku.settings(locals())
Now Move your application folder into fresh folder just copy and paste from pycharm projects ;
Since, you are now moving onto the production site, the ‘DEBUG’ in ‘settings.py’ should be set as ‘FALSE’
DEBUG = False
Now Open Gitbash From the newfresh folder that you have copied from Pycharm Projects
Provide command as ‘git init’ in order to initialize a new or empty repository as shown below. Note: Execute all this git commands in Gitbash not pycharm;
git init
Give command ‘git add .’ as shown below in order to add or take all files from your directory.
git add .
Execute command as provided below (git commit -m “deploy”) for creating a snapshot of currently staged changes of the project.
git commit -m “deploy”
So, to login to Heroku, you are required to provide the following command. Also Execute this in Gitbash;
heroku login
after this command press any button to login, and it’ll take you to browser;
After you have executed the command ‘heroku login’, in the web browser, you are now redirected to the page as shown in the image below. Here, you are required to click on the ‘Log In’ button.
After the successfully log in, you are now redirected to the page as shown in the image below.
Now exit that page and com back to gitbash you’ll be logged in sucessfully;
And in Gitbash just press control+C to terminate and go to another command execution;
Now, you are required to create an app in Heroku. Hence, for the stated purpose you are required to execute the following command.
heroku create app_name
There would be chance that your app name would be taken by others, so if taken then try to use different unique names;
Now, for deploying your application you are required to execute the following command.
git push heroku master
So, to commit initial migration on the Heroku application you are required to execute the following query.
heroku run python manage.py migrate
Finally, you can execute the following command to view your Django application.
heroku open
You are required to allocate the allowed hosts or domain which your Django application serves. You also take the following code as the reference to update your ‘ALLOWED_HOSTS’ in ‘settings.py’ file.
Here in allowed_hosts list area you should pass the url which heroku gave, just copy that link from browser which opened after executing “heroku open”
ALLOWED_HOSTS = [''] #just pass that link inside of this strings
Also, you can obtain the URL of your application while creating the application;
Now, you are required to execute the following commands.
git add .
git commit -m “edit”
git push heroku master
After making the required configurations regarding ALLOWED_HOSTS, you can now view your application after executing the following command.
heroku open