Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图制作一个 Cherry Py 页面,该页面将在一周中的某一天将客户重定向到某个站点。我试过这样做webbrowser.open('sitename.com'),但这只是在控制台中打开了网站。有没有办法让它重定向?注意:这是托管在我有异地而不是客户端的 Linux 机器上。感谢所有帮助!
webbrowser.open('sitename.com')
自从我玩 CherryPy 以来已经有一段时间了,但我认为以下应该可以工作:
raise cherrypy.HTTPRedirect("www.newsite.com")
@EricS 答案是完全正确的并且有效,但您需要注意它默认为 303 http 错误代码。如果您需要 301 或 302,您需要执行以下操作:
raise cherrypy.HTTPRedirect("www.newsite.com", status=301)