0

I'm a newbie to Flask so I'm trying to wrap my head around this problem.

I'm trying to make a simple request using the following URL:

@app.route("/home/components/<component_name>")
def get_component(component_name):
  #do something
  return component_data

Which would yield all the data related to a component used in my project.

Problem is, all component names use slashes (ie: "Process/Newday", "Exe/ADM1/polling") which makes it impossible to pass them through the url, so what I'd need is something akin to this:

@app.route("/<components>/*args")
def get_component(args):
  component_name = ""
  for arg in args:
    component_name += "/{}".format(arg)
  #do something
  return component_data

However despite searching here and there I can't find a feasible way to achieve this

someCoder
  • 185
  • 3
  • 15

1 Answers1

1

Have you considered using query parameters instead?

from flask import request

@app.route("/home/components")
def get_component():
    component_name = request.args.get('name')

and then access that address like:

yourdomain.com/home/components?name="Exe/ADM1/polling"

Note that otherwise, unless the number of slashes is fixed, there is no proper way for slack to know which slash is a separator and which is a part of the parameter

Or Y
  • 2,088
  • 3
  • 16
  • Didn't try although I looked for something that would act as such but I clearly couldn't word it correctly on google. As I said, I'm the newbiest newbie you can find on this stuff, all I know when it comes to web app is some html and some rusty java servlet stuff. But yes, this is exactly what I wanted, thank you! – someCoder Sep 01 '20 at 15:32
  • @kn0bbulo You are Welcome :) Good luck! – Or Y Sep 01 '20 at 15:35