1


I have a question about Django allauth-app. I have set up the allauth-app and have a standard login. Now I would like to store some additional information on signup. To be precise I would like to store the User's city, firstname and lastname. I tried to accomplish this task as explained in

How to customize user profile when using django-allauth

But even if I try to capture the first- and lastname where I shouldnt probably create a model, I fail due to this error:

    'module' object has no attribute 'CharField'

I have put new fields in the form and did this:

ACCOUNT_SIGNUP_FORM_CLASS = 'yourproject.yourapp.forms.SignupForm'

Since I am using Django for a couple of days now it might be something very basic that I miss and I do try to read manuals but I am not close to solving this and I decided to ask you for help. Thanks in advance.

my forms.py look like this:

from django.forms import *   

class SignupForm(forms.Form):
    first_name = forms.CharField(max_length=30, label='Voornaam')
    last_name = forms.CharField(max_length=30, label='Achternaam')

def signup(self, request, user):
    user.first_name = self.cleaned_data['first_name']
    user.last_name = self.cleaned_data['last_name']
    user.save()

my models.py looks like this:

from django.db import models
from django.contrib.auth.models import User
from django.db import models
from allauth.account.models import EmailAddress

class Profile(models.Model):
    user = models.OneToOneField(User, verbose_name=_('user'), related_name='profiles')          
    first_name=models.CharField(_("First Name"), max_length=150)
    last_name=models.CharField(_("Last Name"), max_length=150)

The error appears in this line:

 first_name = forms.CharField(max_length=30, label='Voornaam')

Aftermath --> The import statement in my forms is wrong. It should rather look like this:

formy.py:

from django import forms
Community
  • 1
  • 1
Vollmilchbb
  • 481
  • 6
  • 20

1 Answers1

0

The way you're importing the forms module is likely the issue. You either want to do:

from django.forms import CharField

where you explicitly import the fields you want to use

or preferably:

from django import forms

if you just want to import them all.

onyeka
  • 1,517
  • 13
  • 18
  • I swapped the line "from django.forms import *" with "from django.forms import forms" but unluckily I'm still getting the same Error namely: 'module' object has no attribute 'CharField' – Vollmilchbb Apr 28 '15 at 07:09
  • But that's not what I wrote in my answer. You want to use `from django import forms` – onyeka Apr 28 '15 at 07:10
  • Oh, Im sorry I didn't realize that. That indeed fixed my problem. By the way what is the difference here? django.forms and forms are two different things? – Vollmilchbb Apr 28 '15 at 07:22
  • I'll be honest, I'm not 100% sure. I think it has to do with the way django's sub modules are structured. For most other things, saying `from app.module import *` should work. – onyeka Apr 28 '15 at 07:28