का उपयोग करके पंजीकरण के बाद सीधे उपयोगकर्ता को कैसे लॉगिन करें django जेनेरिक CreateView के साथ मैं एक नया उपयोगकर्ता खाता बना सकता हूं, लेकिन मैं इस तकनीक का उपयोग करके पंजीकरण के बाद स्वचालित रूप से इस उपयोगकर्ता को कैसे लॉगिन कर सकता हूं?Django: जेनेरिक CreateView
urls.py ...
यूआरएल (आर '^ साइनअप/$', SignUpView.as_view(), name = 'user_signup'), ...
views.py
class SignUpView (CreateView) :
form_class = AccountCreationForm
template_name = 'accounts/signup.html'
success_url = reverse_lazy('home')
forms.py
class AccountCreationForm (forms.ModelForm) :
def __init__(self, *args, **kwargs) :
super(AccountCreationForm, self).__init__(*args, **kwargs)
for field in self.fields :
self.fields[field].widget.attrs['class'] = 'form-control'
password1 = forms.CharField(label = 'Password', widget = forms.PasswordInput)
password2 = forms.CharField(label = 'Password confirmation', widget = forms.PasswordInput)
class Meta :
model = User
fields = ('email', 'first_name',)
def clean_password2 (self) :
# Check that the two password entries match
password1 = self.cleaned_data.get("password1")
password2 = self.cleaned_data.get("password2")
if password1 and password2 and password1 != password2:
raise forms.ValidationError("Passwords don't match")
return password
def save(self, commit = True) :
# Save the provided password in hashed format
user = super(AccountCreationForm, self).save(commit = False)
user.set_password(self.cleaned_data[ "password1" ])
if commit:
user.save()
return user
हां, यह वही समाधान है जिसे मैंने ढूंढने के लिए प्रबंधित किया है। मैंने प्रमाणित करने के लिए हैश पास का उपयोग करने का प्रयास करने में भी कुछ समय खो दिया)) –