05 Flask Projects With Source Code
Flask’s lightweight and flexible nature makes it an excellent framework for tackling coding challenges that test your understanding of web development concepts like routing, templating, database integration, authentication, and API handling. Below are five Flask coding challenges, each designed to reinforce key skills while building functional applications. Each challenge includes a problem statement, requirements, a solution with code examples, and explanations to help you learn Flask effectively. The challenges leverage Flask’s core components, powered by Werkzeug for routing and Jinja2 for templating, along with extensions like Flask-SQLAlchemy, Flask-Login, and Flask-WTF.
Challenge 1: Flashcard Study App
Problem Statement: Build a flashcard app where users can create, view, and study flashcards with questions and answers. Users should be able to mark cards as "known" or "unknown" during study sessions.
Requirements:
- Create flashcards with a question and answer.
- Display all flashcards in a list.
- Study mode to view one card at a time and mark as known/unknown.
- Store flashcards in a database.
Solution: Flashcard Study App
# app/__init__.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
def create_app():
"""Initialize the Flask flashcard app."""
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret-key'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///flashcards.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
from app.routes import flashcard_bp
app.register_blueprint(flashcard_bp)
with app.app_context():
db.create_all()
return app
# app/models.py
from app import db
class Flashcard(db.Model):
id = db.Column(db.Integer, primary_key=True)
question = db.Column(db.String(200), nullable=False)
answer = db.Column(db.String(200), nullable=False)
known = db.Column(db.Boolean, default=False)
# app/routes.py
from flask import Blueprint, render_template, request, redirect, url_for
from app import db
from app.models import Flashcard
flashcard_bp = Blueprint('flashcard', __name__, template_folder='templates')
@flashcard_bp.route('/')
def index():
"""Display all flashcards."""
flashcards = Flashcard.query.all()
return render_template('index.html', flashcards=flashcards)
@flashcard_bp.route('/add', methods=['POST'])
def add_flashcard():
"""Add a new flashcard."""
question = request.form.get('question')
answer = request.form.get('answer')
if question and answer:
flashcard = Flashcard(question=question, answer=answer)
db.session.add(flashcard)
db.session.commit()
return redirect(url_for('flashcard.index'))
@flashcard_bp.route('/study')
def study():
"""Study mode: show one unknown flashcard."""
flashcard = Flashcard.query.filter_by(known=False).first()
return render_template('study.html', flashcard=flashcard)
@flashcard_bp.route('/mark/<int:flashcard_id>/<status>')
def mark_flashcard(flashcard_id, status):
"""Mark a flashcard as known or unknown."""
flashcard = Flashcard.query.get_or_404(flashcard_id)
flashcard.known = (status == 'known')
db.session.commit()
return redirect(url_for('flashcard.study'))
# app/templates/index.html
<!DOCTYPE html>
<html>
<head><title>Flashcard App</title></head>
<body>
<h2>Flashcards</h2>
<form method="post" action="{{ url_for('flashcard.add_flashcard') }}">
<input type="text" name="question" placeholder="Question" required>
<input type="text" name="answer" placeholder="Answer" required>
<button type="submit">Add Flashcard</button>
</form>
<ul>
{% for flashcard in flashcards %}
<li>{{ flashcard.question }} - {{ flashcard.answer }} {% if flashcard.known %}(Known){% endif %}</li>
{% endfor %}
</ul>
<a href="{{ url_for('flashcard.study') }}">Start Studying</a>
</body>
</html>
# app/templates/study.html
<!DOCTYPE html>
<html>
<head><title>Study Mode</title></head>
<body>
<h2>Study Mode</h2>
{% if flashcard %}
<p><strong>Question:</strong> {{ flashcard.question }}</p>
<p><strong>Answer:</strong> {{ flashcard.answer }}</p>
<a href="{{ url_for('flashcard.mark_flashcard', flashcard_id=flashcard.id, status='known') }}">Mark Known</a>
<a href="{{ url_for('flashcard.mark_flashcard', flashcard_id=flashcard.id, status='unknown') }}">Mark Unknown</a>
{% else %}
<p>No unknown flashcards left!</p>
{% endif %}
<a href="{{ url_for('flashcard.index') }}">Back to List</a>
</body>
</html>
# run.py
from app import create_app
app = create_app()
if __name__ == '__main__':
app.run()
Setup Command:
pip install flask flask-sqlalchemy
export FLASK_APP=run
flask run
Output: (In browser at /study
)
<h2>Study Mode</h2>
<p><strong>Question:</strong> What is 2+2?</p>
<p><strong>Answer:</strong> 4</p>
<a href="/mark/1/known">Mark Known</a>
<a href="/mark/1/unknown">Mark Unknown</a>
Explanation:
- Database: SQLAlchemy stores flashcards with question, answer, and status.
- Routes: Manage CRUD operations and study mode with Werkzeug.
- Templates: Jinja2 renders flashcards dynamically.
- Challenge Focus: Filtering data (unknown flashcards) and state management.
Challenge 2: Voting Poll App
Problem Statement: Create a voting poll app where users can create polls with multiple options and vote. Display results as a percentage.
Requirements:
- Create polls with a question and options.
- Allow users to vote on options.
- Display poll results with vote percentages.
- Prevent duplicate voting (using session).
Solution: Voting Poll App
# app/__init__.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
def create_app():
"""Initialize the Flask voting poll app."""
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret-key'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///polls.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
from app.routes import poll_bp
app.register_blueprint(poll_bp)
with app.app_context():
db.create_all()
return app
# app/models.py
from app import db
class Poll(db.Model):
id = db.Column(db.Integer, primary_key=True)
question = db.Column(db.String(200), nullable=False)
class Option(db.Model):
id = db.Column(db.Integer, primary_key=True)
text = db.Column(db.String(100), nullable=False)
votes = db.Column(db.Integer, default=0)
poll_id = db.Column(db.Integer, db.ForeignKey('poll.id'), nullable=False)
poll = db.relationship('Poll', backref='options')
# app/routes.py
from flask import Blueprint, render_template, request, redirect, url_for, session
from app import db
from app.models import Poll, Option
poll_bp = Blueprint('poll', __name__, template_folder='templates')
@poll_bp.route('/', methods=['GET', 'POST'])
def index():
"""Display polls and create new ones."""
if request.method == 'POST':
question = request.form.get('question')
options = request.form.getlist('options')
if question and options:
poll = Poll(question=question)
db.session.add(poll)
db.session.flush()
for text in options:
if text:
option = Option(text=text, poll_id=poll.id)
db.session.add(option)
db.session.commit()
polls = Poll.query.all()
return render_template('index.html', polls=polls)
@poll_bp.route('/poll/<int:poll_id>', methods=['GET', 'POST'])
def vote(poll_id):
"""Handle voting and display results."""
poll = Poll.query.get_or_404(poll_id)
if request.method == 'POST':
if f'voted_{poll_id}' not in session:
option_id = request.form.get('option')
option = Option.query.get_or_404(option_id)
option.votes += 1
db.session.commit()
session[f'voted_{poll_id}'] = True
total_votes = sum(option.votes for option in poll.options)
results = [
{'text': option.text, 'votes': option.votes, 'percentage': (option.votes / total_votes * 100) if total_votes else 0}
for option in poll.options
]
return render_template('vote.html', poll=poll, results=results, voted=f'voted_{poll_id}' in session)
# app/templates/index.html
<!DOCTYPE html>
<html>
<head><title>Voting Poll</title></head>
<body>
<h2>Create Poll</h2>
<form method="post">
<input type="text" name="question" placeholder="Question" required><br>
<input type="text" name="options" placeholder="Option 1" required><br>
<input type="text" name="options" placeholder="Option 2" required><br>
<button type="submit">Create Poll</button>
</form>
<h3>Polls</h3>
<ul>
{% for poll in polls %}
<li><a href="{{ url_for('poll.vote', poll_id=poll.id) }}">{{ poll.question }}</a></li>
{% endfor %}
</ul>
</body>
</html>
# app/templates/vote.html
<!DOCTYPE html>
<html>
<head><title>Poll</title></head>
<body>
<h2>{{ poll.question }}</h2>
{% if not voted %}
<form method="post">
{% for option in poll.options %}
<input type="radio" name="option" value="{{ option.id }}" required> {{ option.text }}<br>
{% endfor %}
<button type="submit">Vote</button>
</form>
{% endif %}
<h3>Results</h3>
<ul>
{% for result in results %}
<li>{{ result.text }}: {{ result.votes }} votes ({{ result.percentage | round(2) }}%)</li>
{% endfor %}
</ul>
<a href="{{ url_for('poll.index') }}">Back</a>
</body>
</html>
# run.py
from app import create_app
app = create_app()
if __name__ == '__main__':
app.run()
Setup Command:
pip install flask flask-sqlalchemy
export FLASK_APP=run
flask run
Output: (In browser at /poll/1
)
<h2>Favorite Color?</h2>
<form method="post">
<h3>Results</h3>
<ul>
<li>Blue: 2 votes (66.67%)</li>
<li>Red: 1 vote (33.33%)</li>
</ul>
Explanation:
- Database: SQLAlchemy stores polls and options with vote counts.
- Session: Prevents duplicate voting using session storage.
- Templates: Jinja2 renders polls and results with percentages.
- Challenge Focus: Data aggregation and session management.
Challenge 3: Secret Message Board
Problem Statement: Build a message board where users can post anonymous messages that expire after a set time (e.g., 24 hours). Messages are stored temporarily and deleted automatically.
Requirements:
- Post anonymous messages.
- Messages expire after 24 hours.
- Display active messages.
- Validate message input.
Solution: Secret Message Board
# app/__init__.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
def create_app():
"""Initialize the Flask message board app."""
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret-key'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///messages.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
from app.routes import message_bp
app.register_blueprint(message_bp)
with app.app_context():
db.create_all()
return app
# app/models.py
from app import db
from datetime import datetime, timedelta
class Message(db.Model):
id = db.Column(db.Integer, primary_key=True)
text = db.Column(db.Text, nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
def is_expired(self):
return datetime.utcnow() > self.created_at + timedelta(hours=24)
# app/forms.py
from flask_wtf import FlaskForm
from wtforms import TextAreaField, SubmitField
from wtforms.validators import DataRequired, Length
class MessageForm(FlaskForm):
text = TextAreaField('Message', validators=[DataRequired(), Length(max=500)])
submit = SubmitField('Post')
# app/routes.py
from flask import Blueprint, render_template, redirect, url_for
from app import db
from app.models import Message
from app.forms import MessageForm
message_bp = Blueprint('message', __name__, template_folder='templates')
@message_bp.route('/', methods=['GET', 'POST'])
def index():
"""Display and post messages."""
form = MessageForm()
if form.validate_on_submit():
message = Message(text=form.text.data)
db.session.add(message)
db.session.commit()
return redirect(url_for('message.index'))
messages = Message.query.filter(Message.created_at > datetime.utcnow() - timedelta(hours=24)).all()
return render_template('index.html', form=form, messages=messages)
# app/templates/index.html
<!DOCTYPE html>
<html>
<head><title>Secret Message Board</title></head>
<body>
<h2>Secret Message Board</h2>
<form method="post">
{{ form.hidden_tag() }}
{{ form.text.label }} {{ form.text() }}<br>
{{ form.submit() }}
</form>
<h3>Messages</h3>
{% for message in messages %}
<p>{{ message.text }} (Posted: {{ message.created_at.strftime('%Y-%m-%d %H:%M') }})</p>
{% endfor %}
</body>
</html>
# run.py
from app import create_app
app = create_app()
if __name__ == '__main__':
app.run()
Setup Command:
pip install flask flask-sqlalchemy flask-wtf
export FLASK_APP=run
flask run
Output: (In browser)
<h2>Secret Message Board</h2>
<form method="post">
<h3>Messages</h3>
<p>Hello, world! (Posted: 2025-05-12 10:00)</p>
Explanation:
- Database: SQLAlchemy stores messages with timestamps.
- Expiration: Filters messages to show only those within 24 hours.
- Forms: Flask-WTF validates input for security.
- Challenge Focus: Time-based data filtering and temporary storage.
Challenge 4: Random Quote Generator API
Problem Statement: Create a RESTful API that stores quotes and returns a random quote when requested. Users can also add new quotes via a web interface.
Requirements:
- API endpoint to get a random quote.
- Web interface to add quotes.
- Store quotes in a database.
- Return JSON responses for API.
Solution: Random Quote Generator API
# app/__init__.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
def create_app():
"""Initialize the Flask quote API app."""
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret-key'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///quotes.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
from app.routes import quote_bp
app.register_blueprint(quote_bp)
with app.app_context():
db.create_all()
return app
# app/models.py
from app import db
class Quote(db.Model):
id = db.Column(db.Integer, primary_key=True)
text = db.Column(db.Text, nullable=False)
author = db.Column(db.String(100))
# app/forms.py
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired, Length
class QuoteForm(FlaskForm):
text = StringField('Quote', validators=[DataRequired(), Length(max=500)])
author = StringField('Author', validators=[Length(max=100)])
submit = SubmitField('Add Quote')
# app/routes.py
from flask import Blueprint, render_template, redirect, url_for, jsonify
from app import db
from app.models import Quote
from app.forms import QuoteForm
import random
quote_bp = Blueprint('quote', __name__, template_folder='templates')
@quote_bp.route('/', methods=['GET', 'POST'])
def index():
"""Add new quotes via web interface."""
form = QuoteForm()
if form.validate_on_submit():
quote = Quote(text=form.text.data, author=form.author.data)
db.session.add(quote)
db.session.commit()
return redirect(url_for('quote.index'))
return render_template('index.html', form=form)
@quote_bp.route('/api/random')
def random_quote():
"""Return a random quote as JSON."""
quotes = Quote.query.all()
if not quotes:
return jsonify({'error': 'No quotes available'}), 404
quote = random.choice(quotes)
return jsonify({'id': quote.id, 'text': quote.text, 'author': quote.author})
# app/templates/index.html
<!DOCTYPE html>
<html>
<head><title>Quote Generator</title></head>
<body>
<h2>Add Quote</h2>
<form method="post">
{{ form.hidden_tag() }}
{{ form.text.label }} {{ form.text() }}<br>
{{ form.author.label }} {{ form.author() }}<br>
{{ form.submit() }}
</form>
<p>Test the API: <a href="{{ url_for('quote.random_quote') }}">Get Random Quote</a></p>
</body>
</html>
# run.py
from app import create_app
app = create_app()
if __name__ == '__main__':
app.run()
Setup Command:
pip install flask flask-sqlalchemy flask-wtf
export FLASK_APP=run
flask run
Output: (In browser at /api/random
)
{
"id": 1,
"text": "Be the change you wish to see.",
"author": "Gandhi"
}
Explanation:
- API: Returns JSON with a random quote using Werkzeug routing.
- Database: SQLAlchemy stores quotes.
- Forms: Flask-WTF validates input for the web interface.
- Challenge Focus: Building a RESTful API and random selection.
Challenge 5: Event RSVP App
Problem Statement: Build an app where users can create events and others can RSVP. Authenticated users can create events, and anyone can RSVP with their name and email.
Requirements:
- User authentication for event creation.
- Create events with title, date, and description.
- Allow RSVPs with name and email.
- Display event details and RSVP list.
Solution: Event RSVP App
# app/__init__.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
db = SQLAlchemy()
login_manager = LoginManager()
def create_app():
"""Initialize the Flask RSVP app."""
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret-key'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///events.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
login_manager.init_app(app)
login_manager.login_view = 'auth.login'
from app.routes import auth_bp, event_bp
app.register_blueprint(auth_bp)
app.register_blueprint(event_bp)
with app.app_context():
db.create_all()
return app
# app/models.py
from app import db, login_manager
from flask_login import UserMixin
from datetime import datetime
class User(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(50), unique=True, nullable=False)
password = db.Column(db.String(100), nullable=False)
@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))
class Event(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100), nullable=False)
date = db.Column(db.DateTime, nullable=False)
description = db.Column(db.Text)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
user = db.relationship('User', backref='events')
class RSVP(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(50), nullable=False)
email = db.Column(db.String(100), nullable=False)
event_id = db.Column(db.Integer, db.ForeignKey('event.id'), nullable=False)
event = db.relationship('Event', backref='rsvps')
# app/forms.py
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, DateTimeField, TextAreaField, SubmitField
from wtforms.validators import DataRequired, Length, Email
class LoginForm(FlaskForm):
username = StringField('Username', validators=[DataRequired(), Length(min=3, max=50)])
password = PasswordField('Password', validators=[DataRequired()])
submit = SubmitField('Login')
class EventForm(FlaskForm):
title = StringField('Title', validators=[DataRequired(), Length(max=100)])
date = DateTimeField('Date (YYYY-MM-DD HH:MM)', format='%Y-%m-%d %H:%M', validators=[DataRequired()])
description = TextAreaField('Description')
submit = SubmitField('Create Event')
class RSVPForm(FlaskForm):
name = StringField('Name', validators=[DataRequired(), Length(max=50)])
email = StringField('Email', validators=[DataRequired(), Email()])
submit = SubmitField('RSVP')
# app/routes.py
from flask import Blueprint, render_template, redirect, url_for, request, flash
from flask_login import login_user, logout_user, login_required, current_user
from app import db
from app.models import User, Event, RSVP
from app.forms import LoginForm, EventForm, RSVPForm
import hashlib
auth_bp = Blueprint('auth', __name__, template_folder='templates')
event_bp = Blueprint('event', __name__, template_folder='templates')
@auth_bp.route('/login', methods=['GET', 'POST'])
def login():
"""Handle user login."""
form = LoginForm()
if form.validate_on_submit():
user = User.query.filter_by(username=form.username.data).first()
if user and user.password == hashlib.sha256(form.password.data.encode()).hexdigest():
login_user(user)
return redirect(url_for('event.index'))
flash('Invalid credentials')
return render_template('login.html', form=form)
@auth_bp.route('/logout')
@login_required
def logout():
"""Handle user logout."""
logout_user()
return redirect(url_for('event.index'))
@event_bp.route('/', methods=['GET', 'POST'])
def index():
"""Display events and create new ones."""
form = EventForm()
if form.validate_on_submit() and current_user.is_authenticated:
event = Event(
title=form.title.data,
date=form.date.data,
description=form.description.data,
user_id=current_user.id
)
db.session.add(event)
db.session.commit()
return redirect(url_for('event.index'))
events = Event.query.all()
return render_template('index.html', form=form, events=events)
@event_bp.route('/event/<int:event_id>', methods=['GET', 'POST'])
def event_details(event_id):
"""Display event details and handle RSVPs."""
event = Event.query.get_or_404(event_id)
form = RSVPForm()
if form.validate_on_submit():
rsvp = RSVP(name=form.name.data, email=form.email.data, event_id=event.id)
db.session.add(rsvp)
db.session.commit()
return redirect(url_for(' όλαevent.event_details', event_id=event.id))
return render_template('event.html', event=event, form=form)
# app/templates/login.html
<!DOCTYPE html>
<html>
<head><title>Login</title></head>
<body>
<h2>Login</h2>
{% for message in get_flashed_messages() %}
<p style="color: red;">{{ message }}</p>
{% endfor %}
<form method="post">
{{ form.hidden_tag() }}
{{ form.username.label }} {{ form.username() }}<br>
{{ form.password.label }} {{ form.password() }}<br>
{{ form.submit() }}
</form>
</body>
</html>
# app/templates/index.html
<!DOCTYPE html>
<html>
<head><title>Events</title></head>
<body>
<h2>Events</h2>
{% if current_user.is_authenticated %}
<form method="post">
{{ form.hidden_tag() }}
{{ form.title.label }} {{ form.title() }}<br>
{{ form.date.label }} {{ form.date() }}<br>
{{ form.description.label }} {{ form.description() }}<br>
{{ form.submit() }}
</form>
<a href="{{ url_for('auth.logout') }}">Logout</a>
{% else %}
<a href="{{ url_for('auth.login') }}">Login to create events</a>
{% endif %}
<h3>Upcoming Events</h3>
<ul>
{% for event in events %}
<li><a href="{{ url_for('event.event_details', event_id=event.id) }}">{{ event.title }}</a> ({{ event.date.strftime('%Y-%m-%d %H:%M') }})</li>
{% endfor %}
</ul>
</body>
</html>
# app/templates/event.html
<!DOCTYPE html>
<html>
<head><title>Event Details</title></head>
<body>
<h2>{{ event.title }}</h2>
<p>Date: {{ event.date.strftime('%Y-%m-%d %H:%M') }}</p>
<p>{{ event.description }}</p>
<h3>RSVP</h3>
<form method="post">
{{ form.hidden_tag() }}
{{ form.name.label }} {{ form.name() }}<br>
{{ form.email.label }} {{ form.email() }}<br>
{{ form.submit() }}
</form>
<h3>Attendees</h3>
<ul>
{% for rsvp in event.rsvps %}
<li>{{ rsvp.name }} ({{ rsvp.email }})</li>
{% endfor %}
</ul>
<a href="{{ url_for('event.index') }}">Back</a>
</body>
</html>
# run.py
from app import create_app
app = create_app()
if __name__ == '__main__':
app.run()
Setup Command:
pip install flask flask-sqlalchemy flask-login flask-wtf
export FLASK_APP=run
flask run
Output: (In browser at /event/1
)
<h2>Party</h2>
<p>Date: 2025-06-01 18:00</p>
<p>Join us for fun!</p>
<h3>RSVP</h3>
<form method="post">
<h3>Attendees</h3>
<ul>
<li>Alice (alice@example.com)</li>
</ul>
Explanation:
- Authentication: Flask-Login restricts event creation to logged-in users.
- Database: SQLAlchemy stores events and RSVPs with relationships.
- Forms: Flask-WTF validates input, including email format.
- Challenge Focus: Authentication and multi-model relationships.
Note: For production, use bcrypt for secure password hashing.
Best Practices for Flask Coding Challenges
- Modular Design: Use blueprints and application factories for scalability.
- Security: Validate inputs with Flask-WTF and secure authentication with Flask-Login.
- Testing: Write unit tests with pytest to verify functionality.
- Error Handling: Handle edge cases like empty databases or invalid inputs.
- Avoid Hardcoding: Use configuration files for sensitive data like API keys.
Example: Incorrect Hardcoded Config
# app.py
from flask import Flask
app = Flask(__name__)
app.config['SECRET_KEY'] = 'hardcoded-secret' # Avoid this
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'
@app.route('/')
def index():
return 'Bad Practice'
Explanation:
- Hardcoded secrets are insecure and inflexible.
- Solution: Use
config.py
or environment variables.
Conclusion
These Flask coding challenges—Flashcard Study App, Voting Poll App, Secret Message Board, Random Quote Generator API, and Event RSVP App—provide practical exercises to master Flask’s core features, including Werkzeug routing, Jinja2 templating, and extensions like Flask-SQLAlchemy, Flask-Login, and Flask-WTF. Each challenge targets specific skills, from database filtering to API development and authentication, making them ideal for skill-building and portfolio enhancement. By adhering to best practices like modular design, security, and testing, you can create robust Flask applications.
- Start with Basics: Try the Flashcard or Message Board for core Flask skills.
- Explore APIs: Build the Quote Generator for RESTful API experience.
- Add Complexity: Tackle the RSVP App for authentication and relationships.
- Extend Challenges: Add features like pagination, user registration, or email notifications.
With these coding challenges, you’ll deepen your Flask expertise and be ready for more complex web development projects!
Comments
Post a Comment