error in creating modelform for builtin user table

21 views
Skip to first unread message

shiva kumar

unread,
Nov 28, 2018, 12:45:16 PM11/28/18
to django...@googlegroups.com
hello guys,
       i want to create a register form that user builtin user table . For that i used model form. here is code of forms.

forms.py
from django import forms
from .models import BlogPost
from django.conf import settings
from django.contrib.auth import get_user_model
User=get_user_model()
from django import forms


class register(forms.ModelForm):
class meta:

model=User
fields=['username','first_name','last_name','email','password'
]
password2 = forms.CharField(label='re-enter password', max_length=128)


and i used views.
views.py

def hidemeregister(request):
if request.method == 'POST':
form = register(request.POST)
if form.is_valid():
if form.cleaned_data['password']==form.cleaned_data['password2']:
form.save()
print(type(form))
return redirect('/hideme/blog/')
else:
form=register(get_user_model())
return render(request,'login.html',{'form':form})

and login.html 
i simple used form.as_p in login.html

i am getting error like this

image.png


image.png


please figure out where is the error

here i am using builtin user for register.


amit pant

unread,
Nov 30, 2018, 8:25:00 AM11/30/18
to django...@googlegroups.com
use variable instead of getusermodel

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMsYeuHni67VsJBiWrC6w8seMFN0hpGrqQOJp1sAaSZGLtUHbQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Nagarjuna J

unread,
Nov 30, 2018, 8:30:54 AM11/30/18
to django...@googlegroups.com
i think add password2 in form fileds



For more options, visit https://groups.google.com/d/optout.


--
Thanks&Regards,
-------------------------
J.V.Nagarjuna Reddy,

shiva kumar

unread,
Nov 30, 2018, 8:48:40 AM11/30/18
to django...@googlegroups.com
Ok  thanks guys for ur reply .
But I had found solution.
Just place Meta at meta

amit pant

unread,
Dec 5, 2018, 12:57:58 AM12/5/18
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages