1. A Basic Understanding of Web Service Planning :: Implementing a Web Service with Core Features¶
1.1. MVP (Minimum Viable Product)¶
- A product with only the minimum set of features required for functionality.
- Developed to gather user feedback and gradually improve functionality.
- Commonly used by startups to quickly iterate and improve products.
Core Program Goals
- Develop a blog website with the following features:
- Open the blog page on the web.
- Implement A/B Testing to show different versions of the page to users.
- Add a feature to collect user email subscriptions on each page.
- Save subscribed email addresses to the database.
- Notify users upon subscription confirmation.
- Record and save how many people access each page and at what time.
1.2. Understanding the MVC Pattern for Web Service Implementation¶
- Model-View-Controller (MVC): An architecture derived from software engineering concepts.
- Model: Represents the application's data (usually the database).
- View: Represents the user interface, including text, buttons, etc. (e.g., web pages).
- Controller: Serves as the intermediary between the Model and View, controlling their interaction.
- Writing code in the MVC pattern makes it easier to maintain and extend.
1.3. Features to Implement¶
- Use Flask to develop both the frontend and backend.
- Create two versions of the blog page with only the title changed.
- Implement logic to randomly show one of the two versions (A: 50%, B: 50%) when accessing the same routing path.
- Log the user's IP address and access time.
- Collect and save email addresses upon subscription.
- Ensure that the same blog page is shown for a user after subscription, and the subscription modal no longer appears.
Purpose: After implementing the service, analyzing logs can help determine which blog title attracts more subscribers.
This approach can be extended to create a variety of blog services.
2. MVC Pattern and Flask Blueprint¶
2.1. Challenges of Writing All Code in One File¶
- Writing all code in a single file makes it complex and difficult to manage.
- Always consider reusability.
- However, overly complex architectures are unnecessary for small projects.
2.2. Backend Code Structure in Flask¶
- Separate features into folders/files for better organization (use
blueprint
to simplify adding/removing features). - No direct "View" component for MVC (as the server serves only a REST API for frontend interaction).
- Controller: API logic.
- Model: Database and data modeling.
Key Takeaway: Simple is Best!
2.3. Folder Structure for Feature Separation¶
- For simple codebases, the MVC pattern may slow down implementation since it requires referencing multiple files.
- While MVC is helpful for large-scale systems with complex functionalities, for small projects, a simplified structure is sufficient.
Proposed Structure:

3. Flask Blueprint¶
- Flask
blueprint
allows writing Flask code across multiple source files.
3.1. Main Code File¶
from flask import Flask
from kim[`foldername`] import blog[`filename`] # Replace with the actual folder and file names
app = Flask(__name__)
app.register_blueprint(blog.blog_abtest, url_prefix='/kim')
url_prefix
: Specifies a prefix for all routes defined in the registered blueprint.
For example,/blog
in thekim.py
file will become/kim/blog
.
In [ ]:
# Blue print Example Code
from flask import Blueprint
# Define the blueprint objec
blog_abtest = Blueprint('kim', __name__)
# Example route: http://localhost:5555/kim/blog
@blog_abtest.route('/blog')
def blog():
return "Blueprint Test: Kim's blog"
3.2. Complete Flask Blueprint Example¶
※ Please refer to the folder structure in the image below. To run the application, execute the server.py
script.

Expected Result Page:
In [ ]:
# server.py Example Code
from flask import Flask
# Import the blueprint
from view import blog
app = Flask(__name__)
# Register the blueprint with a prefix
app.register_blueprint(blog.blog_ab, url_prefix='/kim')
if __name__ == '__main__':
app.run(host='0.0.0.0', port='5555')
In [ ]:
# blog.py Example Code
from flask import Blueprint
# Define the blueprint object
blog_ab = Blueprint('kim', __name__)
# Example route: http://localhost:5555/kim/blog
@blog_ab.route('/blog')
def blog():
return 'TEST BLUEPRINT'