Flask:请求静态返回500的子目录

时间:2017-01-02 22:04:03

标签: python flask

我知道,一旦我在生产服务器上运行了所有东西,nginx或apache就应该提供静态资产而不是Flask。为了快速入门,我遇到了Flask问题并请求<?xml version="1.0" encoding="UTF-8" standalone="no"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" encoding="UTF-8" method="xml" /> <xsl:param name="REPORT">joblist</xsl:param> <xsl:param name="LOCALE">en-US</xsl:param> <xsl:param name="FORMAT">html</xsl:param> <xsl:param name="CAPTURE">example,job</xsl:param> <xsl:template match="/"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <title>Joblist Report</title> <style type="text/css"> body {font-family: Arial;} </style> </head> <body> <xsl:apply-templates /> </body> </html> </xsl:template> <xsl:template match="JobList"> <div> <table width="100" border="1"> <thead> <tr> <td> <xsl:value-of select="Sorted Numbers" /> </td> </tr> </thead> <tbody> <xsl:variable name="vsortOrder" select="//Job[@T.number]" /> <xsl:for-each select="Tool"> <xsl:sort select="@number" order="{$vsortOrder}" data-type="number" /> <tr> <td> <xsl:value-of select="@number" /> </td> </tr> </xsl:for-each> </tbody> </table> </div> </xsl:template> </xsl:stylesheet> 子目录中的文件。

static请求正确返回,但/static/test.css请求返回500并抛出此异常:

/static/test/test.css

对该错误进行一些搜索会返回大多数情况,其中有人在请求处理程序中忘记了Traceback (most recent call last): File "/home/tim/shadowcraft-ui-python/venv/lib/python3.5/site-packages/flask/app.py", line 1991, in wsgi_app response = self.make_response(self.handle_exception(e)) File "/home/tim/shadowcraft-ui-python/venv/lib/python3.5/site-packages/flask/app.py", line 1567, in handle_exception reraise(exc_type, exc_value, tb) File "/home/tim/shadowcraft-ui-python/venv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise raise value File "/home/tim/shadowcraft-ui-python/venv/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app response = self.full_dispatch_request() File "/home/tim/shadowcraft-ui-python/venv/lib/python3.5/site-packages/flask/app.py", line 1642, in full_dispatch_request response = self.make_response(rv) File "/home/tim/shadowcraft-ui-python/venv/lib/python3.5/site-packages/flask/app.py", line 1731, in make_response raise ValueError('View function did not return a response') ValueError: View function did not return a response ,但在直接请求资产时没有任何内容。如果尝试在模板中使用return从子目录中请求文件,它也会做同样的事情。

1 个答案:

答案 0 :(得分:0)

这最终导致我的代码出错。我有一个路由处理程序,它将三个部分作为参数,并且由于该处理程序尚未实现,它导致Flask抛出上述异常。我最终为Does Flask support regular expressions in its URL routing?实现了该处理程序的解决方案,因为我知道第一部分总是一些不同的值,static处理程序可以正常运行。