在管理界面中创建新记录时,尝试上载图像时出现以下错误。
Permission denied: '/home/jeffy/django_files/django_test/static/uploaded_files/1407616465_2016587_61DjIaZQI8L.jpg'
相关settings.py
变量:
STATIC_ROOT = "/home/jeffy/django_files/django_test/static/"
MEDIA_ROOT=STATIC_ROOT
的输出
^{pr2}$是
drwxrwxr-x 2 jeffy jeffy 4096 Aug 9 16:32 uploaded_files
服务器以用户jeffy的身份启动:
jeffy@originaldjangster:/etc/nginx/sites-available$ sudo service nginx start
jeffy@originaldjangster:/etc/nginx/sites-available$ sudo /home/jeffy/django_files/django_test_venv/bin/gunicorn -c /home/jeffy/django_files/django_test_venv/gunicorn_config.py django_test.wsgi
root
我把这段代码放在settings.py
的末尾
import getpass
print(getpass.getuser())
这就是为什么“root”会在gunicorn服务器启动后打印出来。
为什么这个文件不能上传?
这是古尼科恩的原版_配置.py文件:
将
nobody
更改为jeffy
可以使其正常工作(尽管它在静态和媒体目录相等的情况下犹豫不决…我在static
旁边创建了一个media
文件夹)。在这个设置只是为了让我炫耀我的Django血统。如果这是一个生产环境,我认为以root用户身份运行服务器是个坏主意。在
不知道这个设置到底有多“糟糕”,但它至少到目前为止是有效的。。。在
相关问题 更多 >
编程相关推荐