Django 上传图片错误之”suspicious operation”
01 Oct 2012错误:安装Python Image Library之后,Django里上传图片出错:suspicious operation
解决:Models.py里的存储路径应该和settings.py里的MEDIA_ROOT保持一致。
我们 的Models.py内容为
from django.db import models from django.contrib import admin class Publisher(models.Model): name = models.CharField(max_length=30) address = models.CharField(max_length=50) city = models.CharField(max_length=60) state_province = models.CharField(max_length=30) country = models.CharField(max_length=50) website = models.URLField() class Author(models.Model): salutation = models.CharField(max_length=10) first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=40) email = models.EmailField() headshot = models.ImageField(upload_to='/z/tmp') class Book(models.Model): title = models.CharField(max_length=100) authors = models.ManyToManyField(Author) publisher = models.ForeignKey(Publisher) publication_date = models.DateField() admin.site.register(Publisher) admin.site.register(Author) admin.site.register(Book)
这里
headshot = models.ImageField(upload_to='/z/tmp')
路径应该与settings.py 的MEDIA_ROOT一致:
MEDIA_ROOT = '/z/tmp'