Social Icons

Saturday, January 22, 2022

Deploy a django project on Heroku


 

We will see in this tutorial, how to deploy a django application on Heroku in step by step details. To start, you must: 

  1. Download and install Git Bush on your machine:  
  2. Download and install Heroku CLI on your machine:

1 - Installing Git on Windows

By default,
Git
is installed on
Linux
and
macOS

computers as a command-line option. However, Microsoft Windows does not include a Git command. Below are the steps to install and use Git and GitHub on Microsoft Windows.  

1 - Open the Git website. 
2 - Click the Download link
to download Git. The download should start automatically.
3 - Once downloaded,
launch the installation from the browser or from the download folder.
4 - In the Window Select Components,
leave all default options checked and check for other additional components you want to install.
5 - Next, in the Default Choice editor
used by Git, unless you're familiar with Vim, we strongly recommend using a text editor you're familiar with. If Notepad++ is installed, we suggest using it as an editor.
6 - Next, in the Adjust your PATH environment, we recommend that you keep Use Git by default in the Windows Command Prompt option selected, as shown below. This option will allow you to use Git from Git Bash or Windows Command Prompt. 




7 - Then we recommend leaving
the default selected under Use OpenSSH.
8 - Then, in Choice of HTTPS transport engine,
leave the default value Use OpenSSL library selected.
9 - In Configure line ending conversions (Checkout Windows-style, commit Unix-style line endings), select the Checkout Windows-style, commit Unix-style line endings option unless you need other line endings for your work.
10 - In the Configure terminal emulator
for use with Git Bash window, select Use MinTTY (the default terminal for MSYS2).
11 - Once done, you can check the Launch Git Bash option
if you want to open a Bash command line or if you have selected the Windows command line running Git from the Windows command line.

Tip:

We strongly recommend using Git from the command line and not using a GUI. You will only use the Git interface command line to manage files. Editing can still be done through a text editor or IDE of your choice.

2 - Install Heroko CLI on your virtualenv

For
Mac OS
, just execute the following command:
brew tap heroku/brew && brew install heroku
For
Ubuntu Linux
, just execute the following command in the teminal shell:
sudo snap install --classic heroku
To install
Heroku CLI
on your
machine Window
, download the application from the link: https://devcenter.heroku.com/articles/heroku-cli#download-and-install launch the app and follow the automated steps.

3 - Creating a new app in heroku

1 - Open your cmd command and navigate with cd to your directory project and activate virtual env 

2 - Login to your heroku account by typing in your cmd:

heroku login
3 - Create a new app in heroku by executing the command:
heroku create your_app_name
If you want to see your app online you must just type in the cmd command:
heroku open --app your_app_name
add your application to the allowed hosts in the settings.py file of your django project:
ALLOWED_HOSTS = ['your_app_name.herokuapp.com','127.0.0.1']

4 - Installing gunicorn and creating a Procfile

To install gunicorn, just run the command:
pip install gunicorn

Now you can create Procfile with content:

web: gunicorn django_project.wsgi

and save the Procfile in root directory of your project. 

 5 - Creating requirement file in the root directory

To notify django of your project's dependencies, please create a requirements.txt file by executing the command:

pip freeze > requirements.txt

6 - Creating  .gitignore file

You can find the content of .gitignore here: https://github.com/github/gitignore/blob/main/Python.gitignore 

7 - Initializing a new git repository

To initialize a new git repository you must execute the command:

git init

8 - Commit and Push repository to online app

Now add all files to git repository by executing the commande:
git add -A
Then commit the selected files by executing the command:
git commit -m "Initial Commit"
And finally push the files in your app online:
git push heroku master
now if everything is correct, your application will be accessible via the link: http://your_app_name.herokuapp.com

Younes Derfoufi
my-courses.net

1 comment:

  1. Wow, excellent post. I'd like to draft like this too - taking time and extremely hard work to make a great article. Visit Alteryx certification sample questions. This post has inspired me to write some posts that I am going to write soon.

    ReplyDelete

Learn Python For Beginners

Category Of Mobile Courses

Actualités (644) Adsense (1) Affiliation (1) Algebraic Topology (2) Algorithmic (1) all-news (30) Android (5) Android App (8) Android app without code (4) Android Apps (256) Android Development (4) Android download (2) Android OS (3) AngularJS (1) Automata theory and formal language (5) Bootstrap CSS (1) C programming (5) Category and Functor (8) CMS (3) Computer Glossary (18) Create Mobile App With Ionic Framework (2) CSS (2) CSS-Cascading-Style-Sheets (4) Developpement Java (13) Differential Geometry (1) Django-Python-Framework (15) dropshiping (26) Earn Money by Internet (4) Emplois (23) Framework php (2) Fraud (2) Github (2) HTML (9) IT News (3) Java For Beginners (10) Javascript (12) Kotlin Programming Language (8) Kotlin For Mobile Android (1) Linux Download (2) Marketing (5) Mobile (3) Mobile Courses (4) Mobile Marketing (4) MoneyGram (1) News (721) Node.js (5) Open Source (1) Photoshop (1) Protect Computer (1) Python (37) Python BeautifulSoup (1) Python For Data Science (2) Python PyQt (13) Python Reference (1) Python Source Code (10) Python-Books (6) Python-DVD-Training (1) Python-Exercises (305) Python-Framework (1) Python-IDE (1) Python-Kivy-Framework (2) Python-Modules (1) Python-pdf (2) Python-pyQt (1) python-temp (3) Référencement (2) Script PHP (2) Security (6) SEO (1) Snipping Tool: Faq (1) Social Networks (1) Source Code (4) Statistics With SPSS (2) Surveillance Software (1) Travail à domicile (6) Tutoriels php en vidéos (2) Tutoriels-MySql (6) tutoriels-php (19) Utilitaires (1) VPS (1) Web Hosting (1) Webcam (1) Webmarketing (11) Western Union (1) Windows 10 (1) Windows 7 (4) Windows 7 Faq (2) Windows 8 (1) Windows Accessories (1) Windows Download (8) Windows Drivers (1) Windows Fonts (1) Windows Power Shell (2) Windows Registry (2) Windows Security (18) Windows Software (2) Windows Spyware (2) Windows utilities (3) Windows Virus (2) Windows Vista (3) Windows Wireless (1) Windows xp (1) Wordpress (1)
 

Sample text

Sample Text

 
Blogger Templates