Answer the question
In order to leave comments, you need to log in
How to register in Djnago?
I have this code:
def register(request):
if request.method =='POST':
form = RegistrationForm(request.POST)
if form.is_valid():
new = form.save(commit=False)
new.save()
# return redirect(reverse('accounts:home'))
return redirect('/home/')
else:
form = RegistrationForm()
args = {
'form': form,
}
return render(request, 'accounts/reg_form.html', args)
class RegistrationForm(UserCreationForm):
email = forms.EmailField(required=True)
class Meta:
model = User
fields = (
'username',
'first_name',
'last_name',
'email',
'password1',
'password2',
)
def save(self, commit=True):
user = super(RegistrationForm, self).save(commit=False)
user.first_name = self.cleaned_data['first_name']
user.last_name = self.cleaned_data['last_name']
user.email = self.cleaned_data['email']
if commit:
user.save()
return user
class UserProfile(models.Model):
user = models.OneToOneField(User)
description = models.CharField(max_length=100, default='')
city = models.CharField(max_length=100, default='')
website = models.URLField(default='')
phone = models.IntegerField(default=0)
image = models.ImageField(upload_to='profile_image', blank=True)
london = UserProfileManager()
def __str__(self):
return self.user.username
Answer the question
In order to leave comments, you need to log in
Well, here it is, in black and white.
https://docs.djangoproject.com/en/2.0/topics/auth/...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question