Getting Started with Flask in Python: A Comprehensive Hindi Tutorial
Are you a Python enthusiast eager to dive into web development? Flask, a popular micro web framework, is an excellent starting point. This comprehensive Flask Python tutorial in Hindi will guide you through the basics, helping you build your first web application in no time. Let's embark on this exciting journey!
Prerequisites
Before we begin, ensure you have the following prerequisites:
- Python 3.6 or later installed on your system.
- Python's package manager, pip, installed.
- A code editor like Visual Studio Code, PyCharm, or Sublime Text.
Setting Up the Environment
First, let's install Flask using pip. Open your terminal or command prompt and type:

pip install flask
To verify the installation, create a new Python file (e.g., app.py) and import Flask:
from flask import Flask

Then, create an instance of Flask and run the application:
app = Flask(__name__)
if __name__ == '__main__':

app.run(debug=True)
Now, run your application using python app.py. Open your browser and visit http://127.0.0.1:5000/ to see "Hello, World!" displayed on the screen.
Routing in Flask
Flask uses decorators to map URLs to Python functions. Let's create a simple route:
@app.route('/')
def home():
return "Hello, World!"
Now, visit http://127.0.0.1:5000/home to see "Hello, World!" displayed again.
Templates and Static Files
Flask uses Jinja2 as its default template engine. Create a new folder named templates in your project directory and add an HTML file (e.g., home.html). Update your home function to render the template:
@app.route('/')
def home():
return render_template('home.html')
In your home.html file, you can use Jinja2 syntax to display dynamic content:
{{ message }}
Now, update your home function to pass a message to the template:
@app.route('/')
def home():
return render_template('home.html', message='Hello, World!')
Forms and User Input
Flask-WTF is a popular extension for handling forms in Flask. First, install it using pip:
pip install flask-wtf
Create a new form (e.g., form.py) and a route to handle the form submission:
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired
class NameForm(FlaskForm):
name = StringField('What is your name?', validators=[DataRequired()])
submit = SubmitField('Submit')
from flask import Flask, render_template, request
app = Flask(__name__)
app.config['SECRET_KEY'] = 'your_secret_key'
from .form import NameForm
@app.route('/', methods=['GET', 'POST'])
def home():
form = NameForm()
if form.validate_on_submit():
return 'Hello, {}!'.format(form.name.data)
return render_template('home.html', form=form)
Conclusion
Congratulations! You've created a simple web application using Flask in Python. This tutorial has barely scratched the surface of what Flask can do. To learn more, explore the official Flask documentation (https://flask.palletsprojects.com/en/2.0.x/) and check out other Flask tutorials in Hindi to further enhance your skills.
![Flask Crash Course For Beginners [Python Web Development]](https://i.pinimg.com/originals/ac/5c/d5/ac5cd516caab7bc9586b4a1ae31283fd.png)





















