Specifying Request Parameters

I am not able to get the most simple example from the documentation to work:
from sanic.response import text

@app.route('/tag/<tag')
async def tag_handler(request, tag):
    return text('Tag - {}'.format(tag))

There are several other examples below specifying the type of the parameter as well. (Several of the handlers have the same name number_handler which is probably a cut and paste error. None of these work either.

I use Postman to send http://ip:port/tag?tag=something
I receive 404: Requested URL not found.

This seems pretty straight forward. Hopefully I’m not just doing something wrong.

Help?

from sanic import Sanic
from sanic.response import text

app = Sanic("test")


@app.route("/tag/<tag>")
async def tag_handler(request, tag):
    return text("Tag - {}".format(tag))


if __name__ == "__main__":
    app.run(debug=True, access_log=True)

And I tested it with curl http://127.0.0.1:8000/tag/example, which works fine for me.

Maybe there is a typo in your @app.route('/tag/<tag') or you are using query parameter(http://ip:port/tag?tag=something) when you making the request. You should send your request to http://ip:port/tag/something instead. If you are trying to use query parameter, you should use the following example instead.

from sanic import Sanic
from sanic.response import json
from sanic.log import logger

app = Sanic("test")


@app.route("/query_string")
def query_string(request):
    logger.warning(request.args)
    return json(
        {
            "parsed": True,
            "args": request.args,
            "url": request.url,
            "query_string": request.query_string,
        }
    )


if __name__ == "__main__":
    app.run(debug=True, access_log=True)

# example
# curl -X GET -H "Accept: application/json" "localhost:8000/query_string?hello=hello&one=one"'"

@github-sjacobs is missing the closing bracket here:

@app.route('/tag/<tag')

it should be

@app.route('/tag/<tag>')

Thanks folks. I actually figured it out this morning just before checking back here. It wasn’t a typo as much as I just didn’t know what I was doing. @shady-robot reply covers my mistake of thinking it was query parameters I was specifying. Sorry.