部署时使用 django admin 上传照片时如何修复权限错误?
How to fix permission error when uploading photos with django admin when deployed?
我正在尝试使用 Django admin 上传照片,但出现以下错误 [Errno 13] Permission denied: '/static'
。
我正在尝试将此项目部署到 Linode 服务器 运行ning ubuntu 18.04 LTS。
我认为这是我对 apache 用户的权限问题,因为如果我 运行 manage.py runserver 0.0.0.0:8000
并通过端口 8000 访问该站点,我可以正常上传照片。我还应该提到,我可以为任何不需要照片的模型使用管理页面。
我已经尝试了任何我可以在网上找到的东西,甚至已经将 777 -R 目录更改为项目。
这是项目的路径:/home/jonny/estate
。
这些是我的家庭目录和庄园目录的权限:
jonny@django-server:~$ ls -la
total 68
drwxrwxrwx 7 jonny jonny 4096 May 4 10:01 .
drwxr-xr-x 3 root root 4096 May 1 17:49 ..
-rwxrwxrwx 1 jonny jonny 4795 May 2 18:13 .bash_history
-rwxrwxrwx 1 jonny jonny 220 May 1 17:49 .bash_logout
-rwxrwxrwx 1 jonny jonny 3771 May 1 17:49 .bashrc
drwxrwxrwx 3 jonny jonny 4096 May 1 18:16 .cache
drwxrwxrwx 10 www-data www-data 4096 May 4 10:10 estate
-rwxrwxrwx 1 jonny jonny 29 May 2 14:04 .gitconfig
-rwxrwxrwx 1 jonny jonny 75 May 2 16:01 .git-credentials
drwxrwxrwx 3 jonny jonny 4096 May 1 17:50 .gnupg
drwxrwxrwx 3 jonny jonny 4096 May 1 19:23 .local
-rwxrwxrwx 1 jonny jonny 807 May 1 17:49 .profile
-rwxrwxrwx 1 jonny jonny 7 May 1 18:10 .python_history
drwxrwxrwx 2 jonny jonny 4096 May 1 17:53 .shh
-rwxrwxrwx 1 jonny jonny 1675 May 1 17:57 .ssh
-rwxrwxrwx 1 jonny jonny 0 May 1 17:59 .sudo_as_admin_successful
-rwxrwxrwx 1 jonny jonny 3989 May 4 10:01 .viminfo
jonny@django-server:~/estate$ ls -la
total 300
drwxrwxrwx 10 www-data www-data 4096 May 4 10:10 .
drwxrwxrwx 7 jonny jonny 4096 May 4 10:01 ..
drwxrwxrwx 4 jonny jonny 4096 May 2 13:57 api
-rwxrwxrwx 1 jonny www-data 253952 May 4 10:10 db.sqlite3
drwxrwxrwx 3 jonny jonny 4096 May 2 16:01 estate
drwxrwxrwx 8 jonny jonny 4096 May 2 16:01 .git
-rwxrwxrwx 1 jonny jonny 30 May 1 18:07 .gitignore
drwxrwxrwx 3 jonny jonny 4096 May 1 18:07 .idea
-rwxrwxrwx 1 jonny jonny 626 May 1 18:07 manage.py
-rwxrwxrwx 1 jonny jonny 89 May 1 18:16 requirements.txt
drwxrwxrwx 7 www-data jonny 4096 May 1 18:07 static
drwxrwxrwx 8 www-data varwwwusers 4096 May 1 18:19 staticfiles
drwxrwxrwx 5 jonny jonny 4096 May 1 18:07 ui
drwxrwxrwx 6 jonny jonny 4096 May 1 18:13 venv
这些是我在 settings.py 中的静态设置:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles/')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static/'),
]
这是我的 apache 配置文件:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
Alias /static /home/jonny/estate/staticfiles
<Directory /home/jonny/estate/staticfiles>
Require all granted
</Directory>
<Directory /home/jonny/estate/estate>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/jonny/estate/estate/wsgi.py
WSGIDaemonProcess estate python-path=/home/jonny/estate python-home=/home/jonny/estate/venv
WSGIProcessGroup estate
</VirtualHost>
任何帮助都将不胜感激。这是我第一次部署 Django 项目,我很迷茫。抱歉,如果我遗漏了任何信息或遗漏了一些非常明显的信息。
错误就像django 显示的那样简单。如果你要从网站上传,你应该使用 media
。 static
用于加载静态文件,这些文件最初直接添加到目录中,用户不会更改。如果您通过网站向服务器添加任何文件,只需使用 media
。 static vs media | static_files_in_django | media_files_in_django(simpleisbetter)
我正在尝试使用 Django admin 上传照片,但出现以下错误 [Errno 13] Permission denied: '/static'
。
我正在尝试将此项目部署到 Linode 服务器 运行ning ubuntu 18.04 LTS。
我认为这是我对 apache 用户的权限问题,因为如果我 运行 manage.py runserver 0.0.0.0:8000
并通过端口 8000 访问该站点,我可以正常上传照片。我还应该提到,我可以为任何不需要照片的模型使用管理页面。
我已经尝试了任何我可以在网上找到的东西,甚至已经将 777 -R 目录更改为项目。
这是项目的路径:/home/jonny/estate
。
这些是我的家庭目录和庄园目录的权限:
jonny@django-server:~$ ls -la
total 68
drwxrwxrwx 7 jonny jonny 4096 May 4 10:01 .
drwxr-xr-x 3 root root 4096 May 1 17:49 ..
-rwxrwxrwx 1 jonny jonny 4795 May 2 18:13 .bash_history
-rwxrwxrwx 1 jonny jonny 220 May 1 17:49 .bash_logout
-rwxrwxrwx 1 jonny jonny 3771 May 1 17:49 .bashrc
drwxrwxrwx 3 jonny jonny 4096 May 1 18:16 .cache
drwxrwxrwx 10 www-data www-data 4096 May 4 10:10 estate
-rwxrwxrwx 1 jonny jonny 29 May 2 14:04 .gitconfig
-rwxrwxrwx 1 jonny jonny 75 May 2 16:01 .git-credentials
drwxrwxrwx 3 jonny jonny 4096 May 1 17:50 .gnupg
drwxrwxrwx 3 jonny jonny 4096 May 1 19:23 .local
-rwxrwxrwx 1 jonny jonny 807 May 1 17:49 .profile
-rwxrwxrwx 1 jonny jonny 7 May 1 18:10 .python_history
drwxrwxrwx 2 jonny jonny 4096 May 1 17:53 .shh
-rwxrwxrwx 1 jonny jonny 1675 May 1 17:57 .ssh
-rwxrwxrwx 1 jonny jonny 0 May 1 17:59 .sudo_as_admin_successful
-rwxrwxrwx 1 jonny jonny 3989 May 4 10:01 .viminfo
jonny@django-server:~/estate$ ls -la
total 300
drwxrwxrwx 10 www-data www-data 4096 May 4 10:10 .
drwxrwxrwx 7 jonny jonny 4096 May 4 10:01 ..
drwxrwxrwx 4 jonny jonny 4096 May 2 13:57 api
-rwxrwxrwx 1 jonny www-data 253952 May 4 10:10 db.sqlite3
drwxrwxrwx 3 jonny jonny 4096 May 2 16:01 estate
drwxrwxrwx 8 jonny jonny 4096 May 2 16:01 .git
-rwxrwxrwx 1 jonny jonny 30 May 1 18:07 .gitignore
drwxrwxrwx 3 jonny jonny 4096 May 1 18:07 .idea
-rwxrwxrwx 1 jonny jonny 626 May 1 18:07 manage.py
-rwxrwxrwx 1 jonny jonny 89 May 1 18:16 requirements.txt
drwxrwxrwx 7 www-data jonny 4096 May 1 18:07 static
drwxrwxrwx 8 www-data varwwwusers 4096 May 1 18:19 staticfiles
drwxrwxrwx 5 jonny jonny 4096 May 1 18:07 ui
drwxrwxrwx 6 jonny jonny 4096 May 1 18:13 venv
这些是我在 settings.py 中的静态设置:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles/')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static/'),
]
这是我的 apache 配置文件:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
Alias /static /home/jonny/estate/staticfiles
<Directory /home/jonny/estate/staticfiles>
Require all granted
</Directory>
<Directory /home/jonny/estate/estate>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/jonny/estate/estate/wsgi.py
WSGIDaemonProcess estate python-path=/home/jonny/estate python-home=/home/jonny/estate/venv
WSGIProcessGroup estate
</VirtualHost>
任何帮助都将不胜感激。这是我第一次部署 Django 项目,我很迷茫。抱歉,如果我遗漏了任何信息或遗漏了一些非常明显的信息。
错误就像django 显示的那样简单。如果你要从网站上传,你应该使用 media
。 static
用于加载静态文件,这些文件最初直接添加到目录中,用户不会更改。如果您通过网站向服务器添加任何文件,只需使用 media
。 static vs media | static_files_in_django | media_files_in_django(simpleisbetter)