From efd3070fa6271a77f880367e812130a9da771fcb Mon Sep 17 00:00:00 2001 From: Alaa Aqeel Date: Wed, 17 Jan 2018 11:14:15 +0300 Subject: [PATCH] Create methods.py --- flask/models/methods.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 flask/models/methods.py diff --git a/flask/models/methods.py b/flask/models/methods.py new file mode 100644 index 00000000..d58497d0 --- /dev/null +++ b/flask/models/methods.py @@ -0,0 +1,29 @@ +from flask.templating import render_template + + +class Router(): + + def __init__(self,app): + self.app = app + + def get(self,path,function=None,html=None): + if function == None: + func = lambda **kw:render_template(str(html),**kw) + if self.app.view_functions.get(html): + func = self.app.view_functions.get(html) + + self.app.add_url_rule(path,html,func,methods=["GET"]) + + else: + self.app.add_url_rule( path,function.__name__,function,methods=["GET"]) + + + def post(self,path,function): + self.app.add_url_rule(path,function.__name__,function,methods=["POST"]) + + def put(self,path,function): + self.app.add_url_rule( path, function.__name__, function, methods=["PUT"]) + + def delete(self,path,function): + self.app.add_url_rule( path, function.__name__, function, methods=["DELETE"]) +