Django-Registrierung & amp; Django-Profile, benutze dein eigenes benutzerdefiniertes Formular

Bin ich die Nutzung von django-registration und django-Profil-handle-Registrierung und-profile. Ich würde gern ein Profil für den Benutzer zum Zeitpunkt der Registrierung. Erstellt habe ich ein benutzerdefiniertes Formular, und fügte hinzu, dass die urls.py mit dem Lernprogramm auf:

http://dewful.com/?p=70

Die grundlegende Idee, im tutorial ist das überschreiben der Standard-Anmeldeformular zu erstellen, das Profil in der gleichen Zeit.

forms.py - In meinem profile app

from django import forms
from registration.forms import RegistrationForm
from django.utils.translation import ugettext_lazy as _
from profiles.models import UserProfile
from registration.models import RegistrationProfile

attrs_dict = { 'class': 'required' }

class UserRegistrationForm(RegistrationForm):
    city = forms.CharField(widget=forms.TextInput(attrs=attrs_dict))

    def save(self, profile_callback=None):
        new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],
        password=self.cleaned_data['password1'],
        email=self.cleaned_data['email'])
        new_profile = UserProfile(user=new_user, city=self.cleaned_data['city'])
        new_profile.save()
        return new_user

In urls.py

from profiles.forms import UserRegistrationForm

und

url(r'^register/$',
                           register,
                           {'backend': 'registration.backends.default.DefaultBackend', 'form_class' : UserRegistrationForm},
                           name='registration_register'),

Wird das Formular angezeigt, und ich kann geben Sie in der Stadt, jedoch nicht speichern oder erstellen Sie den Eintrag in der DB.

InformationsquelleAutor der Frage ismail | 2010-04-08

Schreibe einen Kommentar