Flask
Well, Flask is a lightweight web framework that allows you to build web apps with minimal code. As for why I'm working on it, I'm keeping it private for now. Please note that the following code is a small excerpt from the official documentation and contains my own subjective opinions. Lightweight doesn't mean low learning cost; if necessary, please refer to the official documentation.
Custom path parameter converter for URL routing:
from werkzeug.routing import BaseConverter
# Inherit BaseConverter and override regex rules
class PhoneConverter(BaseConverter):
regex = r"1[3-9]\d{9}"
# Inherit BaseConverter and override to_python()
class LsConverter(BaseConverter):
def to_python(self, value):
return value.split(",")
# Register custom converters with Flask's URL map
app.url_map.converters["phone"] = PhoneConverter
app.url_map.converters["ls"] = LsConverter
# Route using phone number converter
@app.route("/<phone:phonenum>")
def index(phonenum):
return f"Hello, {phonenum}!"
# Route using list converter
@app.route("/<ls:elements>")
def index(elements):
return f"List: {elements}"