Apache或Python不会在媒体文件夹中导入图像。当我尝试上传某些内容时返回500错误。
Django在CentOS 7上使用mod_wsgi在Apache背后工作.Django也可以在虚拟环境中工作。我禁用了所有防火墙(selinux,firewalld和iptables)我给了Apache项目文件夹的每个权限。 ( chown apache:apache 和 chmod 777 我仅对媒体文件夹应用了公共写入权限)
这是我项目的apache conf文件:
<VirtualHost *:80>
ServerAdmin webmaster@domain.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/html
Alias /static/ /var/www/example.com/html/static/
Alias /media /var/www/example.com/html/media
<Location "/static/">
Options -Indexes
</Location>
<Directory /var/www/example.com/html/logging>
<Files debug.log>
Require all granted
</Files>
</Directory>
<Directory /var/www/example.com/html>
<Files db.sqlite3>
Require all granted
</Files>
</Directory>
<Directory /var/www/example.com/html/media>
Require all granted
</Directory>
<Directory /var/www/example.com/html/media/uploads>
Require all granted
</Directory>
<Directory /var/www/example.com/html/static>
Require all granted
</Directory>
<Directory /var/www/example.com/html/example>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess example.com python-path=/var/www/example.com/html:/var/www/example.com/html/env/lib/python3.4/site-packages
WSGIProcessGroup example.com
WSGIScriptAlias / /var/www/example.com/html/example/wsgi.py
#Log Settings
ErrorLog "/etc/httpd/logs/example_error"
CustomLog "/etc/httpd/logs/example_acess" combined
</VirtualHost>
model.py
from django.db import models
from services.file_extentions import validate_image_extention
# Create your models here.
class FotografModel(models.Model):
"""Model definition for GaleriModel."""
# TODO: Define fields here
foto = models.ImageField(verbose_name="Fotoğraf", upload_to='uploads/fotograflar/', max_length=100, height_field=None, width_field=None, validators=[validate_image_extention])
foto_baslik = models.CharField(verbose_name="Fotoğraf Açıklaması (Görme Engelliler için)", max_length=100, blank=True, null=True)
olusturulma_tarihi = models.DateTimeField(editable=False, auto_now_add=True, null=True, verbose_name="Oluşturulma tarihi")
guncelleme = models.DateTimeField(auto_now=True, null=True, auto_now_add=False, verbose_name="Son güncelleme", editable=False)
class Meta:
"""Meta definition for FotografModel."""
verbose_name = 'Fotoğraf'
verbose_name_plural = 'Fotoğraflar'
def image_tag(self):
path = "/media/"+str(self.foto)
return u'<img src="%s" style="height:80px!important;height:auto;"/>' % (path)
image_tag.short_description = "Fotoğraf"
image_tag.allow_tags = True
def __str__(self):
return "%s" % (self.foto_baslik)
from django.db.models.signals import pre_delete
from django.dispatch.dispatcher import receiver
@receiver(pre_delete, sender=FotografModel)
def fotograf_delete(sender, instance, **kwargs):
# Pass false so FileField doesn't save the model.
instance.foto.delete(False)
调试日志
from . import _imaging as core
ImportError: cannot import name '_imaging'
当我在虚拟环境中打开shell并尝试使用此代码from PIL import _imaging
时,它运行良好。该项目使用的是4.3.0版本的Pillow包。