From Novice to Web Developer: My First Web-application Journey with Flask

From Novice to Web Developer: My First Web-application Journey with Flask

Project: Flask Virtual Market

ยท

4 min read

1. Introduction

Embarking on a journey to build my first-ever Flask-based web application using Python was a thrilling experience in the world of web development. In this blog post, I'll share my experiences, challenges, and triumphs throughout the development process, hoping to inspire others to take their first steps into web development with Flask.

2. Getting Started with Flask

The journey began with diving into Flask, a lightweight and powerful web framework for Python. Exploring various online resources, I grasped the fundamentals of Flask, such as routing, templates, and integrating databases. The clear explanations and practical examples provided by these resources set a strong foundation for my learning process.

# Import the Flask class from the flask module
from flask import Flask

# Create an instance of the Flask class
app = Flask(__name__)

# Define a route and a function to handle the route
@app.route('/')
def home_page():
    return 'Welcome to my Flask-based web application!'

3. Navigating Through Challenges

Like any learning journey, I encountered challenges during the development process. From debugging mysterious errors to understanding complex concepts, it was sometimes frustrating. However, with the support of online forums and communities, I was able to overcome these hurdles and grow as a developer.

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)

# Replace 'your_database_uri' with the actual URI of your database
app.config['SQLALCHEMY_DATABASE_URI'] = 'your_database_uri'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

# Create an instance of the SQLAlchemy class
db = SQLAlchemy(app)

class User(db.Model) :
    id = db.Column(db.Integer(), primary_key=True)
    user_name = db.Column(db.String(length=40), nullable=False, unique=True)
    email_address = db.Column(db.String(length=50), nullable = False, unique = True)
    password_hash = db.Column(db.String(length=60), nullable=False)
    budget = db.Column(db.Integer(), default = 1000, nullable = False)
    # Here backreference helps us to find the items owned by the user and lazy is important for db to understand
    items = db.relationship('Item', backref="owned_user", lazy=True)

class Item(db.Model) :
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(length=30), nullable=False, unique=True)
    barcode = db.Column(db.String(length=12), nullable=False, unique=True)
    price = db.Column(db.Integer(), nullable=False)
    description = db.Column(db.String(length=1024))
    owner = db.Column(db.Integer(), db.ForeignKey("user.id"))

4. Implementing Features Step by Step

I took a step-by-step approach, starting with the basic functionalities, such as user registration and login, and gradually expanded my web application's capabilities. By exploring online tutorials and documentation, I enhanced the user experience and security of my application.

from flask_login import LoginManager, login_required
login_manager = LoginManager(app)

# Sample route to display home_page
@app.route('/home')
def home_page():
    return render_template('home.html', tasks=tasks)

# Sample route to display market_page
@app.route('/market')
@login_required
def market_page():
    return render_template('market.html', tasks=tasks)


# Sample route for user registration
@app.route('/register', methods=['GET', 'POST'])
def register_page():
    # Implementation of user registration logic
    pass

# Sample route for user login
@app.route('/login', methods=['GET', 'POST'])
def login_page():
    # Implementation of user login logic
    pass

5. Integrating External Libraries

As my project grew, I explored integrating external libraries to further extend the functionality of my Flask-based application. These libraries proved to be valuable assets, enriching the overall user experience.

# Sample libraries (there are many more...)
# Install Flask-WTF library to handle forms
# Run this in the terminal: pip install Flask-WTF
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField
from wtforms.validators import DataRequired, Email, EqualTo

6. Deployment & Future Plans

Currently the application is not hosted/deployed in any platform but in near future I might deploy it after adding some of the functionalities like User Profile, Customizations and many more....

Some of the planned enhancements include:

  • Improved user interface and design.

  • Advanced search and filtering options for products.

  • User ratings and reviews for sellers and products.

  • Real-time notifications for transactions.

  • Enhanced user profiles with customization options.

7. Conclusion

Building my first Flask-based web application with Python was an enriching experience that allowed me to delve into the world of web development. With the abundance of online resources, I discovered the power of self-directed learning and the supportive developer community.

Moreover, I'd like to express my gratitude to the JimShapedCoding YouTube channel and its comprehensive Flask tutorial, which played a pivotal role in helping me achieve this remarkable milestone.

I hope my journey inspires others to take the leap into web development and explore the endless possibilities that Flask has to offer. I'm excited to continue my journey, exploring new technologies and building more projects in the future.

For code snippet, checkout my GitHub Repository

Enjoyed the article? Follow me on:

ย