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.
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
orpython app.py
depending on your Python installation.
Test the app by going into your browser: http://127.0.0.1:5555/home
blade@aelo.io
Trouble? Email Blade Nelson:Expected Output:
If Flask & Python are working as expected, you should see this output:
Navigate to http://127.0.0.1:5555/home (default port is 5555 and the example route in app.py is /home)
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!
Thanks for this informative blog. It was really beneficial blog.
Also,check https://www.iteducationcentre.com/python-training-in-nagpur.php
I really like reading through a post that can make people think. Also, many thanks for permitting me to comment!
https://infocampus.co.in/web-development-training-in-bangalore.html
https://infocampus.co.in/web-designing-training-in-bangalore.html
https://infocampus.co.in/front-end-development-course-in-bangalore.html
https://infocampus.co.in/reactjs-training-in-marathahalli-bangalore.html
https://infocampus.co.in/javascript-jquery-training-in-bangalore.html
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
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/