'SignUpForm'对象没有属性'get'

时间:2015-08-28 22:10:15

标签: python django django-models

我尝试使用注册表单开发一个django项目。用户输入其信息并提交表单后,将为该用户分配用户uuid。错误是:'SignUpForm'对象没有属性'get' 这是我的models.py:

class SignUp(models.Model):
    customer_name=models.CharField(max_length=100,blank=False, primary_key=True)
    customer_website_url=models.CharField(max_length=200, blank=True)
    account_manager_email = models.EmailField(blank=False)
    customer_uuid= models.CharField(max_length = 32)
    timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
    def __unicode__(self):

        return self.customer_uuid

my forms.py:

class SignUpForm(models.ModelForm):
    class Meta:
        model= SignUp
        fields=['customer_name',
            'customer_website_url',
            'account_manager_email',
            ]

     def clean_account_manager_email(self):
        account_manager_email = self.cleaned_data.get('account_manager_email')
        if not "google" in account_manager_email:
            raise forms.ValidationError("Please use a valid email address")
        return account_manager_email        



    def __init__ (self, *args, **kwargs):
        super(SignUpForm, self).__init__(self, *args, **kwargs)
        self.uuid = random_uuid = uuid.uuid4().hex



    def save(self, commit=True):
        signup = super(SignUpForm,self).save(commit = False)
        signup.customer_uuid = self.uuid
        signup.save()
        return signup

回溯:

File "/Library/Python/2.7/site-packages/Django-1.8.3-py2.7.egg/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/Users/user/Documents/work/src/info/views.py" in home
  32.   if form.is_valid(): 

File "/Library/Python/2.7/site-packages/Django-1.8.3-py2.7.egg/django/forms/forms.py" in is_valid
  184.         return self.is_bound and not self.errors

File "/Library/Python/2.7/site-packages/Django-1.8.3-py2.7.egg/django/forms/forms.py" in errors
  176.             self.full_clean()

File "/Library/Python/2.7/site-packages/Django-1.8.3-py2.7.egg/django/forms/forms.py" in full_clean
  392.         self._clean_fields()

File "/Library/Python/2.7/site-packages/Django-1.8.3-py2.7.egg/django/forms/forms.py" in _clean_fields
  401.             value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name))

File "/Library/Python/2.7/site-packages/Django-1.8.3-py2.7.egg/django/forms/widgets.py" in value_from_datadict
  223.         return data.get(name, None)

Exception Type: AttributeError at /

Exception Value: 'SignUpForm' object has no attribute 'get'

提前致谢!我的django版本是1.8.3 python版本:2.7.6

1 个答案:

答案 0 :(得分:2)

问题是你在super()调用中包含public class Structure< T, S> : IStructure<S> where S : StructureStats, new() where T : StructureModel<S>, new() { protected T _model; public S Stats { get { return _model.Stats; } set { _model.Stats = value; } } } public interface IStructure<S> where S : StructureStats { S Stats { get; set; } } 作为参数。它应该是:

self