我正在开发一个 Django 应用程序,它以各种形式显示数据,包括表格和条形图。它使用 matplotlib 将条形图创建为 png。然后它使用以下代码返回它:
.
.
.
canvas=FigureCanvas(fig)
response=HttpResponse(mimetype='image/png')
canvas.print_png(response)
return response
当我使用内置的 Django 开发服务器时,一切正常。但是,当我使用:
python manage.py run_gunicorn
除条形图外,一切正常。我看到的不是条形图,而是 URL。我是否必须运行 nginx 才能让 gunicorn 显示 png 图像,还是我还缺少其他东西?
编辑
卷曲的输出:
About to connect() to 127.0.0.1 port 8000 (#0)
* Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 8000 (#0)
> GET /myapps/bar_chart1 HTTP/1.1
> User-Agent: curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18
> Host: 127.0.0.1:8000
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: gunicorn/0.12.1
< Date: Mon, 16 May 2011 14:05:00 GMT
< Connection: close
< Transfer-Encoding: chunked
< Content-Type: image/png
<
* Leftovers after chunking. Rewinding 16379 bytes
* Closing connection #0