Create Basic Web Application đĽď¸ and đDeploymentđ Using Python!!

Hello Guys!!! đ¤
Today you are going to get introduce yourself to Flask for Python and create a basic web application for âCredit score ratingâ which includes an HTML template containing the structure of a web page, a CSS stylesheet containing design instructions, a Python backend that communicates with a web server and tops it off by deploying this application for free to Heroku! đ
Quick Overview of Flask
- HTML â Flask is using a programming language called HTML to create a structure of a web page.
- CSS â It is used to style this structure and make it look more attractive.
- Javascript â It is used to interact with the different elements on the web page.
- Python â It is used to communicate with the webserver also known as backend. It is only a tiny fraction of Flask.
All the files are available at my GitHub repository.
Follow the steps to get your web app ready!
- Create Folders â First, create an empty folder â CreditScoreRatingAppâ on your PC. Inside it create other folders like:
- âtemplatesâ to store all our HTML files,
- âstaticâ â inside it create âCSSâ folder to save all our stylesheets,


2. âtemplatesâ folder for HTML file â Open a new notepad file and copy the below HTML code.
Save it in the âtemplatesâ folder with âindexâ name and extension as â.htmlâ.

If you click on index.html, it will show below the web page.

3. âstaticâ â âCSSâ folder for CSS file â Open a new file in notepad and copy the below CSS code.
Save it in the âCSSâ folder with the âmainâ name and extension as â.cssâ.
4. In the âCreditScoreRatingAppâ folder, add Python fileâ Open a new file in Spyder or any other Python IDE to create the âapp.pyâ file and copy the below Python code.
If user input is, it will show respective messages:
- 300 to 349â âYour score is Poor!!!â
- 350 to 599â âYour score is Average!!!â
- 600 to 799 â âYour score is Good!!!â
- 800 to 900 â âYour score is Excellent!!!â
- Anything except above will show input is invalid and the max limit is 900 and the min limit is 300.
5. In the âCreditScoreRatingAppâ folder add .flaskenv file â Open a new file in notepad and copy the below code.
FLASK_APP = app.py
6. Now open the Anaconda command prompt and create a new virtual environment with the below commands:
conda create â name env2 (please check exact syntax below)

Then activate your newly created environment with the below line of code:
conda activate env2
You need to install flask on the new environment with the below code:
conda install -c anaconda flask
Now go to your directory of the âCreditScoreRatingAppâ folder. cd for change directory:
cd Downloads\Web App\CreditScoreRatingApp
Type flask run and hit enter.

Go to URL âhttp://127.0.0.1:5000/priyankadâ

Enter a value in empty input box e.g. 850 and hit SUBMIT button.

Your webpage is completely functional now.
đ¤ Remember if you make any changes to HTML, CSS or Python file then to you need to clear cache â Go to Settings option n Chrome â Privacy and security â clear browsing data â Cached images and files â Clear data.
You need to create two additional files:
- Procfile:
On the Anaconda prompt, type Ctrl + C to quit. Then install gunicorn using:
pip install gunicorn
Type below to create a new empty file in the same folder directory
echo > Procfile
Go to âCreditScoreRatingAppâ folder and open âProcfileâ with notepad and delete text âECHO is on.â and type âweb: gunicorn app:appâ where first app is for your Python file name âapp.pyâ and save it.
2. Requirements file
To generate requirements file where all the requirements of your application get automatically generated â type below and hit enter:
pip freeze > requirements.txt

Deployment using HEROKU đ
Go to âhttps://www.heroku.comâ and login or sign up for new free account. Once you have created a new account, navigate to your dashboard on clicking on grid icon:

Click on âCreate a new appâ and app name and choose a region then click on âCreate appâ.

Go to settings:

Scroll a bit below and click on âAdd buildpackâ and select Python and save changes:


Scroll up and click on âDeployâ:

We will connect and deploy our application using Github â Click on GitHub then click on âConnect to GitHubâ and give your Username and password.

Give your repository name and click on âConnectâ.

Go to âManual deployâ section and select whichever branch you need as I will select âmainâ and click on âDeploy Branchâ.

Scroll a bit down:

Once you see âDeploy to Herokuâ message, click on âViewâ and you will see below webpage:

Remember that you have to specify â/priyankadâ route in the URL:

Voila!!! đ
____________________________________________________________
Thanks for reading â¤
For any suggestions or queries, leave your comments below and follow for updates.
If you liked the article, please hit the đ icon to support it. This will help other Medium users find it. Share it, so that others can read it!
Happy Learning! đ