0

如果我这样做runservergunicorn直接从命令行执行,则该网站可以正常工作。但是,如果我尝试使用Heroku 文档中指定的 Foreman 运行 gunicorn :

web: gunicorn myapp.wsgi

然后我网站的静态文件突然无法访问了;想去

http://0.0.0.0:5000/static/js/jquery-1.9.1.min.js

只给我这个错误信息:

Using the URLconf defined in myapp.urls, Django tried these URL patterns, in this order:

    ^$ [name='homepage']
    ...

The current URL, static/js/jquery-1.9.1.min.js, didn't match any of these.

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

正如我所说,如果直接调用 gunicorn 或 runserver ,或者即使使用runserverwith ,静态文件肯定是可以访问的foreman start,所以我猜它与我的静态文件设置没有太大关系?

此外,除了 500 错误之外,在工头上运行 gunicornDEBUG = False甚至不会返回任何内容。没有任何记录,甚至在 Sentry 上也没有,所以我不知道出了什么问题。它也可以单独使用 gunicorn 或 runserver,或者将 runserver 与工头一起使用。

有什么想法可以解决这个问题吗?

4

2 回答 2

1

不知道为什么没有检索到静态文件,但DEBUG = False500 错误只是由我的ALLOWED_HOSTS设置引起的,修复它不会产生进一步的问题。

于 2013-04-10T08:18:47.657 回答
0

我会在 gunicorn 下运行时尝试打印设置,看看您的媒体 URL 是否正确以及 js 文件是否确实可以访问。

至于 500 错误,它可能试图向您显示 404 页面,但您没有它的模板,因此它会引发 500 和旧的 django 怪癖;)

PS。这一切都假设您在该错误中验证了正确的 URL 模式

于 2013-04-08T07:04:15.363 回答