sanic-org / sanic

Accelerate your web app development | Build fast. Run fast.
https://sanic.dev
MIT License
18k stars 1.54k forks source link

Using app.static twice reports a deprecation warning #2674

Closed jschewebbn closed 1 year ago

jschewebbn commented 1 year ago

Is there an existing issue for this?

Describe the bug

I am serving 2 different static directories, when calling app.static a second time I get a warning:

DeprecationWarning: [DEPRECATION v23.3] Duplicate route names detected: __main__.static. In the future, Sanic will enforce uniqueness in route naming.

Code snippet

app = Sanic(__name__)
app.static('/static', str(SCRIPT_DIR.joinpath('static_content').resolve()))
app.static('/static_common', str(SCRIPT_DIR.joinpath('../common_content').resolve()))

Expected Behavior

No response

How do you run Sanic?

As a script (app.run or Sanic.serve)

Operating System

Linux

Sanic Version

v22.12.0

Additional context

No response

Tronic commented 1 year ago

Both routes are named static, which is why you get that warning. Provide a different name for at least one of them:

app.static('/static', staticdir)
app.static('/static_common', staticdir, name='static_common')

Closing as not a bug. For support issues, please refer to Sanic Community Forums

jschewebbn commented 1 year ago

@Tronic how do I specify another name? "static" is a special function on app. I'm not aware of how to do this. Can you point me at documentation or an example?

ahopkins commented 1 year ago

This issue has been mentioned on Sanic Community Discussion. There might be relevant details there:

https://community.sanicframework.org/t/using-app-static-twice-reports-a-deprecation-warning/1146/1