Django TypeError in forms.py

By rohillasarthak

I am deploying my django app on pythonanywhere.com and get this error while doing signup of user TypeError at /registration/ argument 1 must be str, not list.

I am checking if user already present in database then throw validation error in forms.py.

The error is suspected due to this code.

forms.py

class SignUpForm(forms.Form):
email = forms.EmailField(max_length=254, help_text='Required. Inform a valid email address.')
name = forms.CharField(max_length=100, required=False, help_text='Required.')
password = forms.CharField(max_length=1000, required=False, help_text='Required.')
role = forms.CharField()
def clean(self):
    cleaned_data = super(SignUpForm, self).clean()
    name = cleaned_data.get("name")
    email = cleaned_data.get("email")
    password = cleaned_data.get("password")
    role = cleaned_data.get("role")
    # validate email
    if role == 'Author':
        user = UserSignup.objects.filter(email=email)
        #error suspected here--
        if user.first() is not None:
            raise forms.ValidationError(
                "Email already registered. Try again.")
    elif role == 'Publisher':
        user = PubSignup.objects.filter(email=email)
        if user.first() is not None:
            raise forms.ValidationError(
                "Email already registered. Try again.")
class Meta:
    model = UserSignup
    fields = ('email', 'name', 'password')

views.py

if form.is_valid():
        if form.role == "Author":
            p = UserSignup(
                name=form.cleaned_data.get('name'),
                email=form.cleaned_data.get('email'),
                password=form.cleaned_data.get('password')
            )
            p.save()
            success = True
        elif form.role == "Publisher":
            p = PubSignup(
                name=form.cleaned_data.get('name'),
                email=form.cleaned_data.get('email'),
                password=form.cleaned_data.get('password')
            )
            p.save()
            success = True

Source: Stack Overflow

    

Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273