ImportError:无法导入名称ValidatedFile

时间:2013-09-23 02:16:53

标签: python django

我是一个新的django / python开发人员。我试图限制可以上传到某个扩展名的文件类型。我发现了django-validated-file 2.0应用程序将执行此操作,但是当我尝试使用它时,我收到以下错误。

“ImportError:无法导入名称ValidatedFileField”

我已经尝试了我能找到的每种导入变体。

感谢任何和所有帮助。

这是我的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'])

0 个答案:

没有答案