can someone help me with my code? Why is it not working?
My views.py
def register(request):
if request.method == 'POST':
form = RegisterForm(request.POST)
if form.is_valid():
fullname = form.cleaned_data.get('fullname')
emailaddress = form.cleaned_data.get('emailaddress')
password = form.cleaned_data.get('password')
form.save()
return redirect('/')
else:
form = RegisterForm()
return render(request, 'register.html', {'form': form})
forms.py
class RegisterForm(forms.Form):
fullname = forms.CharField(label='fullname', max_length=100)
emailaddress = forms.EmailField(label='emailaddress', max_length=150)
password = forms.CharField(label='password', max_length=100)
Thanks a lot!
Can’t seem to connect the inputed data into the db…
2
Answers
If you wish to save data to database by using
Django Forms
then its better to useModelForm
. Instead of inheriting the class fromforms.Form
useModelForm
for examplechange according to your use case. for more information check the documentation django modelform
If you wish to implement a custom user authentication model (both registration and login) use bellow link to know more.
extending user model
You can try another method also
If you want to use same method, share your error message