Python 使用nginx从django下载Excel时出错
使用nginx提供服务的django服务器使用pandas和BytesIO创建一个excel文件,然后返回一个HttpRespose,如下所示:Python 使用nginx从django下载Excel时出错,python,django,excel,nginx,gunicorn,Python,Django,Excel,Nginx,Gunicorn,使用nginx提供服务的django服务器使用pandas和BytesIO创建一个excel文件,然后返回一个HttpRespose,如下所示: data=export\u data.export\u data() response=HttpResponse(数据,content_type='application/vnd.openxmlformats of icedocument.spreadsheetml.sheet') 响应['Content-Disposition']='附件;filen
data=export\u data.export\u data()
response=HttpResponse(数据,content_type='application/vnd.openxmlformats of icedocument.spreadsheetml.sheet')
响应['Content-Disposition']='附件;filename=“Download.xlsx”'
返回响应
模板具有引用此视图的锚定。
这只适用于django(本地测试)
但在生产中(使用nginx),它给了我以下错误:
The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.
NGINX配置:
upstream my-server {
server unix:/tmp/gunicorn.sock fail_timeout=0;
}
server {
listen 8000;
server_name 11.11.1.3;
keepalive_timeout 5;
client_max_body_size 4G;
access_log /my-server/logs/nginx.access.log;
error_log /my-server/logs/nginx-error.log;
location /static/ {
alias /my-sever/static/;
}
location /media/ {
alias /my-server/media/;
}
location / {
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://my-server;
}
}
请帮我解决这个问题。
提前感谢您如果您指定
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet会发生什么;charset=utf-8'
?@physicalattraction此端没有任何更改,仍然是相同的错误