我是一个新的 django / python 开发人员。我正在尝试限制可以上传到某个扩展名的文件类型。我找到了可以执行此操作的 django-validated-file 2.0 应用程序,但是当我尝试使用它时,出现以下错误。
“ImportError:无法导入名称 ValidatedFileField”
我已经尝试了所有我能找到的 import 变体。
任何和所有的帮助表示赞赏。
这是我的 requirements.txt 我正在使用 python 2.7
Django==1.5.2
South==0.8.2
distribute==0.7.3
django-html5-boilerplate==1.0.5
django-markdown-deux==1.0.4
django-tables2==0.14.0
django-validated-file==2.0
markdown2==2.1.0
mysql-python==1.2.4
pillow==2.1.0
python-magic==0.4.3
six==1.4.1
这是 settings.py 文件的一部分。
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'media',
'south',
'plugin',
'PIL',
'markdown_deux',
'django_tables2',
'validatedfile',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
)
这是我的模型的相关部分。
from django.db import models
from validatedfile import ValidatedFileField
from django.contrib.auth.models import User
from PIL.Image import core
# Create your models here.
class Plugin(models.Model):
pluginTitle = models.CharField(max_length=255, unique=True)
pluginUrl = models.TextField()
pluginLanguage = models.ForeignKey('media.Language')
pluginAuthor = models.ForeignKey(User,related_name='pluginAuthor')
pluginWebsite = models.CharField(max_length=255)
pluginInstructions = models.TextField()
pluginFile = ValidatedFileField(
null = True,
blank = True,
upload_to = 'files/',
max_upload_size = 52428800,
content_types = ['text/groovy'])
#models.ValidatedFileField(upload_to='files/', max_upload_size=52428800, content_types = ['text/groovy'])
pluginLogo = models.ImageField(upload_to='images/')
pluginStatus = models.ForeignKey('plugin.Status')
pluginType = models.ForeignKey('plugin.PluginType')
pluginRevisionDate = models.DateField()
pluginSourceLocation = models.CharField(max_length=255)
pluginVersion = models.IntegerField ()
pluginDescription = models.TextField()
pluginApiName = models.CharField(max_length=255, unique=True)
createdBy = models.ForeignKey(User,related_name='plugin_createdBy')
createdOn = models.DateField()
modifiedBy = models.ForeignKey(User,related_name='plugin_modifiedBy')
modifiedOn = models.DateField()
def __unicode__(self):
return self.pluginTitle
这是文件的开发人员说要做的事情。
from django.db import models
from validatedfile import ValidatedFileField
class TestModel(models.Model):
the_file = ValidatedFileField(
null = True,
blank = True,
upload_to = 'testfile',
max_upload_size = 10240,
content_types = ['image/png'])