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
  IndexError: list index out of range" & "TypeError: The view function f: Flask Web App joelbeater992 5 860 Aug-31-2021, 08:08 PM
Last Post: joelbeater992
  how to pass javascript variables to url_for function in a flask template experimental 5 3,365 Oct-29-2020, 03:29 AM
Last Post: universe
  flask webhook response onicode5476 1 974 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 825 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 1,264 May-01-2020, 05:50 PM
Last Post: Larz60+
  Create .exe file for Python flask website. vintysaw 4 11,119 Nov-18-2019, 07:56 AM
Last Post: tonycstech
  How to create Flask-Stripe Checkout and Charge for the multiple items Antares 4 3,332 Jul-05-2019, 10:20 AM
Last Post: Antares
  flask-SQLAlchemy query with keyword as function argument pascale 2 2,036 Mar-13-2019, 08:45 PM
Last Post: Ecniv
  unable to call function in Flask verb 5 13,608 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