1
As you have not mentioned what is the error that was raised. Here is my take on the question.
Using Django Forms or HTML forms should not be any different.
class SignupForm(forms.ModelForm):
class Meta:
model = get_user_model()
fields = ('username', 'email', 'phone', 'country',)
When you create a django form, it just creates a html element like:
<input type="text" name="username" id="id_username">
<input type="email" name="email" id="id_email">
<input type="text" name="phone" id="id_phone">
<input type="text" name="country" id="id_country">
So you can just make sure the name attribute of the element is same as the model attribute name. And you can create your own form in forms.py as you have already done.
And in your views:
if request.method == "POST":
register_form = RegisterForm(request.POST)
if register_form.is_valid():
register_form.save()
return redirect("home")
If you completely want to skip forms.py, then you can manually create save form creating instances like:
if request.method == "POST":
username = request.POST.get("username")
email= request.POST.get("email")
phone= request.POST.get("phone")
country= request.POST.get("country")
User.objects.create(
email=email, username=username, phone=phone, country=country
)
Please check this out as well. https://stackoverflow.com/a/50404014/10669512
Source:stackexchange.com