Django上传文件保存到共享文件夹

问题遇到的现象和发生背景

客户要实现一个功能,在画面把文件拖拽进去,点击保存,将上传进去的文件,保存到共享文件夹里。如果共享文件夹下,没有执行时对应年的文件夹,先创建对应年份的文件夹,再把上传的文件保存到对应年份的文件夹下。
例:
执行时间是:2021年12月27日,那么就把文件保存到,'//192.168.XX.60/保管_支付/2021/'这个文件夹下。
执行时间是:2022年01月15日,那么就把文件保存到,'//192.168.XX.60/保管_支付/2022/'这个文件夹下。
注:这个192.168.XX.60跟部署的服务器ip‘192.168.xx.119不是一个。并且远程的文件夹访问没有用户名密码,guest模式就可以访问。也可以设置成用id,和密码访问

部署后的页面访问url:http://192.168.XX.119/.省略了

需求描述完,说一下我遇到的问题。
我在本地测试环境中,用python manage.py runserver命令启动Django项目,访问网页保存均没有问题。
但是当我把Django项目部署到运用环境时,就怎么都写不进去。

其中我注意到的是,下面这个方法
if not os.path.exists(file_root_path):
os.mkdir(file_root_path)
这个路径无论存在还是不存在,这个os.path.exists()在运用环境里都返回的是FALSE,在单机的测试环境里就可以正常判断,存在返回TRUE,不存在返回FALSE。

运用环境
OS:Windows Server 2012 R2 Standard

问题相关代码,请勿粘贴截图

settings.py里
FILE_CHANGE_PAY_ROOT = '//192.168.XX.60/保管_支付'

view.py里

处理 POST 请求

if request.method == 'POST':
    # 获取画面上传文件
    files = request.FILES.getlist('pay_file')
    if len(files):
        # 目录路径
        file_root_path = os.path.join(FILE_CHANGE_PAY_ROOT, '2021')
        # 没有该文件夹创建文件夹
        if not os.path.exists(file_root_path):
            os.mkdir(file_root_path)
运行结果及报错内容

因为部署环境无论目标path存在还是不存在,os.path.exists(file_root_path)都返回的是FALSE,所以总会执行到os.mkdir(file_root_path)这里。
就会报下边的错误。

ERROR 2021-12-27 10:19:00,511 Internal Server Error: /eigyosystem/changefilename/changefilepay/
Traceback (most recent call last):
File "c:\python38\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "c:\python38\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "c:\python38\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "c:\python38\lib\contextlib.py", line 75, in inner
return func(*args, **kwds)
File "C:\inetpub\wwwroot\SOGX\Xsystem\X\changefilename\views.py", line 50, in changefilepay
os.mkdir(file_root_path)
PermissionError: [WinError 5] 拒绝访问: '//192.168.XX.60/保管_支付\2021'

将路径的中文改为英文试试

你要访问的共享文件夹,你看看你有没有写入,删除权限。