Codementor Events

Python Flask Tutorial: How to Make a Basic Page (Source Code Included!) πŸ“ƒπŸ‘¨β€πŸ’»

Published Jul 07, 2020Last updated Jan 02, 2021
Python Flask Tutorial: How to Make a Basic Page (Source Code Included!) πŸ“ƒπŸ‘¨β€πŸ’»

Python Flask is a crucial tool I use daily to prototype my ideas and bring a product to market faster than triditional methods like PHP or Ruby.

These benefits make it the ideal tool for small teams or startups trying to get an MVP off the ground. It removes the need to worry about complexities and just focus on making cool websites. Today I am going to show you how to make a basic page in Flask and pass input back through to a Python function on the backend.

Download Source Code Button.png

What is Python Flask?

Flask is a library for Python. Flask gives Python the ability to serve HTML pages using Python as a webhost. This means you can use Python as the backend for your website and HTML / JS for the frontend. This stack has become very popular in recent years and has seen an increase in documentation and examples on GitHub and YouTube. These factors make Flask a great tool to add to your toolbox of programming knowledege. (See my GitHub for a demo!) https://github.com/powderblock/Python-Flask-Boilerplate/ Follow me for cool new projects every week! πŸ˜‰

Python Flask can be daunting for new programmers.

This simple Flask example is a beginner template intended to showcase the basics of Flask's routing and rendering system.

Take note of the render_template file structure. You can use this project as a building block for more complex web apps! πŸ˜ƒ

Currently, this example page will render a page (templates/index.html) which has the ability to call a function in the app.py from Javascript.

It is a cool basic example and serves a useful purpose. Please message me on CodeMentor if you have any problems running the code or with your addtions! I'll try and respond to as many people as possible.

How to install Flask?

To install Flask, open Terminal or CMD.

Type the following command to install the Flask library using the PIP package manager:

pip install Flask

Example Project:

Python 3+

Flask is the only required library.

πŸ”Œ Example Usage:

To run this, clone the repo onto your local machine.

https://github.com/powderblock/Python-Flask-Boilerplate

  • Navigate to the repo in terminal or CMD.
  • Run app.py by calling python3 app.py or python app.py depending on your Python installation.

Test the app by going into your browser: http://127.0.0.1:5555/home

Trouble? Email Blade Nelson: blade@aelo.io

Expected Output:

If Flask & Python are working as expected, you should see this output:Image of Output Simple Flask example tutorial template boilerplate github source code

Navigate to http://127.0.0.1:5555/home (default port is 5555 and the example route in app.py is /home)

You should see this page:Flask boilerplate example Python easy for beginners page index.html template route render_template html

Success! βœ…

Next Steps:

This project is a good starter example for anyone to become familar with the basics of Flask's routes and render_template system. A database can be added for creating user accounts. Passwords can be hashed in Python functions. More complex and robust routing strategies can be implemented.

Credits

Made by Blade Nelson in 2020.

Follow me on CodeMentor! πŸ˜ƒ Feel free to message me!

Discover and read more posts from Blade Nelson
get started
post commentsBe the first to share your opinion
iteducationcentre
6 months ago

Thanks for this informative blog. It was really beneficial blog.
Also,check https://www.iteducationcentre.com/python-training-in-nagpur.php

Infocampus 2000
9 months ago
Vijaya Sanap
3 years ago

Your blog is very effective and glad to read, really it’s pretty awesome and gives lots of valuable ideas for web app development. It will be very useful for Web app developers.

https://www.technobridge.in/full-stack-developer-course.html

fusion technology ankush
a year ago

Thank you so much for sharing this valuable knowledge with us. This is an excellent blog that you have created. I thoroughly loved your essay. I’ll be looking forward to your next post.

https://ankushblog713309085.wordpress.com/
https://ankushfusiontechnology.blogspot.com/
https://fusiontechnologyankush.tumblr.com/

Show more replies