0

I have developed a python application which takes in post variables and inserts data into postgresql. Now I want to call specific function when we call a url.

For example

if  I do
  curl -i http://127.0.0.1:5000/abc/cde
  it should call 
   def aaa()
  if curl -i http://127.0.0.1:5000/pqr/xyz
  it should call 
  def bbb()

is there a way to achieve that in python flask web frameworks ?

Matthew Trevor
  • 14,354
  • 6
  • 37
  • 50
Error_Coding
  • 273
  • 2
  • 4
  • 13

1 Answers1

2

This is the one of the main features of a web framework. The most minimal example in Flask would be:

# my_app.py

from flask import Flask
app = Flask(__name__)

@app.route('/abc/cde')
def aaa():
    return 'Hello, this is aaa'

@app.route('/pqr/xyz')
def bbb():
    return 'Hello, this is bbb'

if __name__ == '__main__':
    app.run()

You can then run this:

$ python my_app.py

Like any Python script. I suggest you have a look at Flask's Quickstart page as a starting point.

s16h
  • 4,647
  • 1
  • 21
  • 33