Getting Started with Flask: Hello, World! on GitHub
Welcome to the world of Flask, a lightweight and flexible Python web framework. In this guide, we'll create a simple "Hello, World!" application and host it on GitHub. Let's dive in!
Setting Up Your Environment
Before we start, ensure you have Python and pip installed on your system. Then, install Flask using pip:
pip install flask
Creating Your First Flask Application
Create a new folder for your project and navigate into it. Then, create a new file called app.py and add the following code:

```python from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, World!' if __name__ == '__main__': app.run(debug=True) ```
This simple application will respond with "Hello, World!" when you navigate to the root URL.
Running Your Application
To run your application, use the following command in your terminal:
python app.py
Then, open your web browser and navigate to http://127.0.0.1:5000/ to see your "Hello, World!" message.

Version Control with Git
It's a good practice to use version control for your projects. Initialize a new Git repository in your project folder:
git init
Add your app.py file and commit the changes:
git add app.py
git commit -m "Initial commit"
Hosting on GitHub
Create a new repository on GitHub, then follow these steps to push your local repository to GitHub:

- Connect your local repository to GitHub:
git remote add origin https://github.com/yourusername/your-repo-name.git - Push your local changes to GitHub:
git push -u origin main
Deploying Your Application
To deploy your Flask application on GitHub, you'll need to use GitHub Pages and a Python runtime. Here's how:
- Create a new branch called
gh-pagesand push it to GitHub:
git checkout -b gh-pages
git push origin gh-pages
- Create a new file called
.github/workflows/flask.ymlin your project root with the following content:
- Commit and push the changes:
git add .github/workflows/flask.yml
git commit -m "Add GitHub Actions workflow for Flask deployment"
git push origin gh-pages
Now, whenever you push changes to the gh-pages branch, GitHub Actions will deploy your Flask application. You can access it at https://yourusername.github.io/your-repo-name/.






















