Creating a Flask App: My issues as a beginner and how I fixed them.
Tags: webdev, beginners, python, learning
Published: 2024-07-02 20:11:22

Hi everyone, **Eworitse Egbejule** here. This is my first blog post and I want to share my experience with creating a flask app; the issues I had while making it and how I fixed them.

Flask is a lightweight and flexible microframework used for building web apps in Python with minimal setup. Here's a sample code of a simple flask web app:

![Sample Flask web app](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x9n2347pkkn3zauusuvo.png)

My app is called Microblog and it's a simple blog flask app with it's frontend self written in HTML and CSS. 

I followed these steps to build my app:

#### Step 1: Design the Frontend

* I started by creating the HTML and CSS code for a simple blog interface.
* The blog lets users record notes in the form of a diary.
* The entries are then presented back to the user in a clean, user-friendly format.

#### Step 2: Develop the Backend
* I followed a tutorial to build the Flask backend. Flask is perfect for this due to its simplicity and flexibility.
*This stage involved setting up routes, handling user inputs, and managing the data.

#### Step 3: Handle Backend Hosting Issues

* The main challenge came with hosting the site. Initially, I attempted to host it on [Render](https://render.com).
* I connected it to my GitHub repo [here](https://github.com/EbiScott/practice-blog), but encountered multiple errors.
* The errors were frustrating, and a friend suggested switching to [Vercel](https://vercel.com). Even on Vercel, I faced troubleshooting issues.

## Steps I took to fix my deployment issues:
* Check app.py File:
I had to check if my Flask app was correctly instantiated as app.

```python
    from flask import Flask

    app = Flask(__name__)

    if __name__ == '__main__':
        app.run()
```

* Updated the gunicorn Command:
I modified the start command in my deployment settings to:
``` bash
    gunicorn app:app
```
* Had to ensure correct Directory Structure:
I checked to make sure that `app.py` is in the root directory of your project.

I created a `vercel.json` Configuration File:

```json
    {
      "version": 2,
      "builds": [
        {
          "src": "app.py",
          "use": "@vercel/python"
        }
      ],
      "routes": [
        {
          "src": "/(.*)",
          "dest": "app.py"
        }
      ]
    }
```

* Push to GitHub and Link to Vercel:
After fixing the issues I pushed my code to GitHub. Then I linked my GitHub repository to Vercel for automatic deployment.



### Deployment: Making It Live
I deployed the application on Vercel and pushing my code to GitHub, followed by linking the repository to Vercel for automatic deployment. You can check out my web app here at [The Microblog](https://the-microblog.vercel.app/).

![Vercel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kji35339m3rxfa8jmm1n.png)


## HNG 11 Backend Internship
The process of building this microblog application strengthened my interest and love for backend development. It taught me valuable lessons in routing, CRUD operations, and deployment. Now, I'm excited to bring this passion and these skills to the HNG Internship.

The HNG Internship provides a great opportunity to learn from experienced professionals, work on practical projects, and connect with other programmers. I'm very much interested in the intensive learning and opportunities that are provided by the internship. In case you're interested and want to find out more information about the program, please checkout [HNG Internship](https://hng.tech/internship) and [HNG Hire](https://hng.tech/hire).

## Conclusion
This project was a significant milestone in my backend development journey. I'm really looking forward to the challenges and learning opportunities that the HNG Internship will bring. If you're also an aspiring developer like me, I highly recommend checking out the HNG Internship to take your skills to the next level.