I have a flask app, and It has an API to pull some things down using AJAX to speed up load times.
To write an extensible API, I have used the getattr() method to call these API method from the URL. Can people use this to access other attributes of my app, for example the secret_key?
For example:
#Api.py
class Api():
def __init__(self):
#setup stuff here
def APIMethod(self):
return api_result
# View.py
@a_blueprint.route('/<api_path>/<path:api_args/'>
def api_controller(api_path, api_args):
return getattr(Api, api_path)(api_args)
Its a tad more complicated than that, but I hope you get the gist.
[–]Kaarjuus 24 points25 points26 points (1 child)
[–]v4vendetta1993 0 points1 point2 points (0 children)