How to customize the parameters of decorators and functions in flask

that"s what the decorator says now

@app.route("/<name>")
@test
def show_name(name):
    return name

error report:

Traceback (most recent call last):
  File "/Users/cevin/Documents/projects/bit/venv/lib/python3.7/site-packages/gunicorn/workers/sync.py", line 135, in handle
    self.handle_request(listener, req, client, addr)
  File "/Users/cevin/Documents/projects/bit/venv/lib/python3.7/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/Users/cevin/Documents/projects/bit/venv/lib/python3.7/site-packages/flask/app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/cevin/Documents/projects/bit/venv/lib/python3.7/site-packages/flask/app.py", line 2295, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/cevin/Documents/projects/bit/venv/lib/python3.7/site-packages/flask/app.py", line 1741, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/cevin/Documents/projects/bit/venv/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/Users/cevin/Documents/projects/bit/venv/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/cevin/Documents/projects/bit/venv/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/cevin/Documents/projects/bit/venv/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/cevin/Documents/projects/bit/venv/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/Users/cevin/Documents/projects/bit/venv/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/cevin/Documents/projects/bit/venv/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
TypeError: deco() got an unexpected keyword argument "name"

Mar.31,2021

change it to solve it like this:

def test(param=None):
    def deco(func):
        def wrapper(*args,**kwargs):
            return func(*args,**kwargs)
        return wrapper
    return deco
    

@app.route('/<name>')
@test(param='xxx')
def show_name(name):
    return name
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3a779-2c231.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3a779-2c231.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?