django项目,本机可以下载,局域网其他机器下载失败

问题描述

Django项目,写了一个下载功能,在本机(linux)下载是可以的,在局域网下载却显示“失败-服务器出现问题”
防火墙已经关闭,打开页面是可以的,就下载文件失败
setting 已经添加ALLOWED_HOSTS = ['*']配置

代码如下:

def downloadfile(req):
  # do something...

  the_file_name = "pyt1/python3.tar"
  def file_iterator(file_name, chunk_size=512):
      with open(file_name,'rb') as f:
          while True:
              c = f.read(chunk_size)
              if c:
                  yield c
              else:
                  break

  the_file_name = "files/python3.tar"
  response = StreamingHttpResponse(file_iterator(the_file_name))
  response['Content-Type'] = 'application/octet-stream'
  response['Content-Disposition'] = 'attachment;filename="{0}"'.format(the_file_name)

  return response

运行项目命令

 python manage.py runserver 192.168.0.105:8081

本机linux截图 :
image

局域网window截图:
img

阅读 1.6k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题