python - How to add a blueprint and a url rule to an extension and not in the flask project -


i trying learn making flask extensions. want after my_extention.init_app(app) in application factory add view in flask-admin. example my_extension.add_view(name='view extension'). create endpoint localhost:5000/myextension/test. again want extension this.

from flask import blueprint, jsonify flask.views import methodview  class flaskmyextension(object):     def __init__(self, app=none):         if app:             self.init_app(app)         self.module = none      def init_app(self, app):         print('[-] extension: registering blueprints')         self.register_blueprint(app)      def register_blueprint(self, app):         self.myextension = blueprint(             "myextension", __name__, template_folder="templates"         )         app.register_blueprint(self.module)         return self.myextension      # def add_view(self):     #     try:     #         self.blueprint.add_url_rule("/test", view_func=test.as_view('test'), methods=['get', 'post', 'put', 'delete'])     #     except exception e:     #         print(e) 

the view be

class test(methodview):      def get(self):         return jsonify({"status":"ok"})      def post(self):         return jsonify({"status":"ok"})      def put(self):         return jsonify({"status":"ok"})      def delete(self):         return jsonify({"status":"ok"}) 

i have templates folder. simple jsonify('you extensions test view') more enough.

thank you


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -