【发布时间】:2020-07-09 03:26:42
【问题描述】:
我在使用 Django Admin 将图像上传到我的生产站点时遇到问题。
我正在使用 sqlite db 运行 Apache HTTPD 服务器。
在运行开发服务器时上传工作正常,但是当我尝试向我的站点添加一个包含图像的新条目时,我收到错误:
PermissionError at /admin/homepage/jumbotron/add/
我已尽我所能研究此错误,但我现在不知所措。
我已经检查了文件权限,包括将组和所有者设置为 http http,这是运行 apache httpd 服务器的用户。
我继续使用 chmod -R 777 暂时授予我的静态文件夹完全权限并重新启动 httpd 服务器,但错误仍然存在。我也进行了完整的系统重启。
当前文件权限为:
drwxrwxr-x 8 http http 4096 Jul 3 16:48 static
我在我的 setting.py 中尝试了其他方法,例如将 STATIC_URL 更改为完整路径或删除第一个斜杠,所以它是静态 /,然后重新启动服务器,什么也没有;没有骰子。
setting.py
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates'), ]
SECURE_SSL_REDIRECT = True
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'homepage',
'blog',
'portfolio',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'blogsite.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
'DIRS': TEMPLATE_DIRS,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'homepage.context_processors.add_navbar_data_to_base'
],
},
},
]
STATIC_URL = 'static/'
我对 httpd.conf 文件进行了一些调整,并在尝试 Require all granted under the /static 文件夹后进入了这些设置
httpd.conf
<VirtualHost *:443>
Alias /static /srv/http/blogsite/static
<Directory /srv/http/blogsite/static>
Order allow,deny
Allow from all
</Directory>
<Directory /srv/http/blogsite/blogsite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess blogsite python-path=/srv/http/blogsite python-home=/srv/http/django
WSGIProcessGroup blogsite
WSGIScriptAlias / /srv/http/blogsite/blogsite/wsgi.py
</VirtualHost>
models.py
class Jumbotron(models.Model):
title = models.TextField(default="")
description = models.TextField()
display_order = models.IntegerField()
slideimage = models.FileField(upload_to="static/homepage")
【问题讨论】: