[英]Django deployed app/project can't write to a file
I am working on a Django based application whose location on my disk is home/user/Documents/project/application
. 我正在使用基于Django的应用程序,该应用程序在磁盘上的位置为home/user/Documents/project/application
。 Now this application takes in some values from the user and writes them into a file
located in a folder
which is under the project
directory ie home/user/Documents/project/folder/file
. 现在,这个应用程序需要从用户一些值,并将其写入到file
位于在folder
这是在project
目录即home/user/Documents/project/folder/file
。 While running the development server using the command python manage.py runserver
everything worked fine, however after deployment the application/views.py
which accesses the file
via open('folder/path','w')
is not able to access it anymore, because by default it looks in var/www
folder when deployed via apache2
server using mod_wsgi
. 使用python manage.py runserver
命令运行开发服务器时,一切正常,但是在部署之后,通过open('folder/path','w')
访问file
的application/views.py
无法再访问它,因为默认情况下,当使用mod_wsgi
通过apache2
服务器进行部署时,它会在var/www
文件夹中查找。
Now, I am not putting the folder
into /var/www
because it is not a good practise to put any python code there as it might become readable clients which is a major security threat. 现在,我不会将folder
放入/var/www
因为在其中放置任何python代码不是一个好习惯,因为它可能会变成可读的客户端,这是一个主要的安全威胁。 Please let me know, how can I point the deployed application to read and write to correct file. 请让我知道,我如何指向已部署的应用程序以读取和写入正确的文件。
The real solution is to install your data files in /srv/data/myapp
or some such so that you can give the webserver user correct permissions to only those directories. 真正的解决方案是将数据文件安装在/srv/data/myapp
或类似文件中,以便您可以仅向Web服务器用户授予对这些目录的正确权限。 Whether you choose to put your code in /var/www
or not, is a separate question, but I would suggest putting at least your wsgi file there (and, of course, specifying your <DocumentRoot..>
correctly. 是否选择将代码放在/var/www
是一个单独的问题,但是我建议至少将wsgi文件放在其中(当然,正确地指定<DocumentRoot..>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.