sanic-org / sanic

Accelerate your web app development | Build fast. Run fast.

Home Page:https://sanic.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using app.static twice reports a deprecation warning

jschewebbn opened this issue · comments

Is there an existing issue for this?

  • I have searched the existing issues

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

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

@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?

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