Created
June 26, 2021 05:34
-
-
Save epsi95/7a0b05337cf6e02716fda3f4c13807f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Flask: | |
def __init__(self, import_name): | |
self.import_name = import_name | |
self.route_mapping = {} # empty dict to store all the route mapping | |
def route(self, route_name): # parameterized decorator | |
def wrapper(view_func): | |
self.route_mapping[route_name] = view_func | |
return view_func # here we are just returning the original function not modifying it | |
return wrapper | |
# just making this function to demonstrate a server request from WSGI server | |
def get_response_for_this_route(self, route_name): | |
try: | |
return self.route_mapping.get(route_name)() | |
except TypeError as e: | |
return '404 requested url not found!' | |
app = Flask(__name__) | |
@app.route('/') | |
def home(): | |
return 'this is home page' | |
@app.route('/signin') | |
def home(): | |
return 'this is signin page' | |
#----------let's test the web app------- | |
print(app.get_response_for_this_route('/')) | |
print(app.get_response_for_this_route('/signin')) | |
print(app.get_response_for_this_route('/route that does not exists')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment