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
new to flask , i have web app that containes few parts
for example:
My Question is how can i make global_response function/handler that can be called from :,, without threading problem
for example:

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

 clas Utils():
          def ORA(self):
             return global_response("error ora","b")
def some_fun(self):
        return global_response("error main","c")
and here is the response function which was in 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:
     return json.dumps(res)
I'd like to suggest that you run through Miguel Grinberg's tutorial here:
Free and well done.
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 ...

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 1,141 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,598 Oct-29-2020, 03:29 AM
Last Post: universe
  flask webhook response onicode5476 1 1,126 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 898 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,352 May-01-2020, 05:50 PM
Last Post: Larz60+
  Create .exe file for Python flask website. vintysaw 4 12,076 Nov-18-2019, 07:56 AM
Last Post: tonycstech
  How to create Flask-Stripe Checkout and Charge for the multiple items Antares 4 3,496 Jul-05-2019, 10:20 AM
Last Post: Antares
  flask-SQLAlchemy query with keyword as function argument pascale 2 2,177 Mar-13-2019, 08:45 PM
Last Post: Ecniv
  unable to call function in Flask verb 5 14,002 Sep-29-2016, 02:27 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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