Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Deploy Machine Learning Model using Flask
Next article icon

Flask is a web application framework written in Python. Flask is based on the Werkzeug WSGI toolkit and Jinja2 template engine. Both are Pocco projects. This article revolves aroundhow to deploy a flask app on Heroku. To demonstrate this, we are first going to create a sample application for a better understanding of the process. 

Prerequisites 


 

Deploying Flask App on Heroku


Let's create a simple flask application first and then it can be deployed to heroku. Create a folder named"eflask" and open the command line and cd inside the"eflask" directory. Follow the following steps to create the sample application for this tutorial.
STEP 1 : Create a virtual environment with pipenv and installFlask andGunicorn.
 

$ pipenv install flask gunicorn


STEP 2 : Create a"Procfile" and write the following code. 
 

$ touch Procfile


 


STEP 3 : Create"runtime.txt" and write the following code.
 

$ touch runtime.txt


 


STEP 4 : Create a folder named"app" and enter the folder. 
 

$ mkdir app
$ cd app


STEP 5 : Create a python file,"main.py" and enter the sample code.
 

 touch main.py


 

Python3
fromflaskimportFlaskapp=Flask(__name__)@app.route("/")defhome_view():return"<h1>Welcome to Geeks for Geeks</h1>"

STEP 6 :Get back to the previous directory "eflask".Create a file"wsgi.py" and insert the following code.
 

$ cd ../
$ touch wsgi.py


 

Python3
fromapp.mainimportappif__name__=="__main__":app.run()

STEP 7 : Run the virtual environment.
 

$ pipenv shell


STEP 8 : Initialize an empty repo, add the files in the repo and commit all the changes.
 

$ git init
$ git add .
$ git commit -m "Initial Commit"


STEP 9 : Login to heroku CLI using 
 

heroku login


Now, Create a unique name for your Web app.
 

$ heroku create eflask-app


 


STEP 10 : Push your code from local to the heroku remote. 
 

$ git push heroku master


 


Finally, web app will be deployed on
http://eflask-app.herokuapp.com//
 


 


Improve
Article Tags :
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp