Python Forum
Flask Create global response function to be called from every where in the web app
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flask Create global response function to be called from every where in the web app
#1
new to flask , i have web app that containes few parts
for example:
    utils/ 
    -- utils.py
    db/ 
    -- oracle.py 
    main.py 
My Question is how can i make global_response function/handler that can be called from : utils.py,oracle.py,main.py without threading problem
for example:
in utils.py

 clas Utils():
      def A(self):
         return global_response("error","a")
oracle.py

 clas Utils():
          def ORA(self):
             return global_response("error ora","b")
main.py
def some_fun(self):
        return global_response("error main","c")
and here is the response function which was in main.py but now needs to be called from any where :

 def global_response(error_msg, title,*options):
        res = {"status": error_msg, "title": title}
    
        for option in options:
            res.update(option)
       
     return json.dumps(res)
Reply
#2
I'd like to suggest that you run through Miguel Grinberg's tutorial here: https://blog.miguelgrinberg.com/post/the...ello-world
Free and well done.
Reply
#3
Thanks for the response , mybe i was misundestod , i do know how to create responses ,
my question is what is the right way to create response handler that i can use from all the web app .
like singletone that contains the global_response fucntion ,
or pass the object to the method that needs to response ...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Flask run function in background and auto refresh page raossabe 2 7,522 Aug-20-2022, 10:00 PM
Last Post: snippsat
  IndexError: list index out of range" & "TypeError: The view function f: Flask Web App joelbeater992 5 3,507 Aug-31-2021, 08:08 PM
Last Post: joelbeater992
  how to pass javascript variables to url_for function in a flask template experimental 5 6,387 Oct-29-2020, 03:29 AM
Last Post: universe
  flask webhook response onicode5476 1 2,509 Aug-29-2020, 03:27 AM
Last Post: onicode5476
  Return Frame as well as JSON response using same API in Flask Python Ask jenkins43 0 1,861 May-11-2020, 04:58 PM
Last Post: jenkins43
  how to create dynamic arguments to be passed in jinja template in url_for function? experimental 1 2,780 May-01-2020, 05:50 PM
Last Post: Larz60+
  Create .exe file for Python flask website. vintysaw 4 19,184 Nov-18-2019, 07:56 AM
Last Post: tonycstech
  How to create Flask-Stripe Checkout and Charge for the multiple items Antares 4 5,266 Jul-05-2019, 10:20 AM
Last Post: Antares
  flask-SQLAlchemy query with keyword as function argument pascale 2 3,477 Mar-13-2019, 08:45 PM
Last Post: Ecniv
  unable to call function in Flask verb 5 18,414 Sep-29-2016, 02:27 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020