Search code examples
pythonsanic

Placeholder in "sanic" python


I've recently been working with the Sanic module in python and I was wondering If there's a way to define placeholders in a url. This is kind of hard to explain but I'm going to try my best.

I want it to be like this kind of. Url: /account/api/public/account/PlaceholderHere/externalAuths Can anyone help me with this?


Solution

  • You can use <> around the placeholder in your route decorator:

    my_route = Blueprint("my_route")
    
    @my_route.route("/account/api/public/account/<placeholder>/externalAuths", methods=["GET"])
    async def get_my_route(request, placeholder):
      print(f"here is my placeholder: {placeholder}")
    

    Read about parameters in the docs.