# Can't register a User using register function

**URL:** <https://forum.djangoproject.com/t/cant-register-a-user-using-register-function/2881>\
**Category:** Using Django\
**Created:** [June 10, 2020, 12:32am UTC](https://forum.djangoproject.com/t/cant-register-a-user-using-register-function/2881 "2020-06-10T00:32:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![valenciano8](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/valenciano8/32/1062_2.png) [@valenciano8](https://forum.djangoproject.com/u/valenciano8)\
**Post date:** [June 10, 2020, 12:32am UTC](https://forum.djangoproject.com/t/cant-register-a-user-using-register-function/2881/1 "2020-06-10T00:32:12Z")

</div>

Hey everyone !

I’m experiencing a weird issue with my register function :

views.py

```auto
    from django.shortcuts import render
    from .forms import SignUpForm, LoginForm

    def registerUser(request):
    if request.method == "POST":
        form = SignUpForm(request.POST)

        if form.is_valid():
            form.save()
            return redirect("/")

        else:
            print(form.errors)
    else:
        form = SignUpForm()

    template_name = "accounts/register.html"
    context = {
        "form":form,
    }

    return render(request, template_name, context)

```

forms.py

```auto
    from django.forms import ModelForm
    from django.contrib.auth.models import User
    from django.contrib.auth.forms import UserCreationForm

    class SignUpForm(UserCreationForm):
    class Meta:
        model = User
        fields = " __all__"

    class LoginForm(ModelForm):
    class Meta:
        model = User
        fields = " __all__"

```

register.html

```auto
    {% extends "base.html" %}

    {% block page_title %}Blog : Register{% endblock %}

    {% block page_content %}
    <form id="registerForm" action="{% url 'accounts:registerUser' %}" method="POST">
    {% csrf_token %}

    {{ form.username.label }}
    {{ form.username }}

    {{ form.email.label }}
    {{ form.email }}

    {{ form.password1.label }}
    {{ form.password1 }}

    {{ form.password2.label }}
    {{ form.password2 }}

    {{ form.errors }}

    <input type="submit" value="Sign Up">
    </form>
    {% endblock %}

```

When I click on the “Sign Up” button on register.html I get (whatever I try to fill in) :

```
password
This field is required.
date_joined
This field is required.

```

Does someone have a clue ?

Thanks !

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 10, 2020, 12:47am UTC](https://forum.djangoproject.com/t/cant-register-a-user-using-register-function/2881/2 "2020-06-10T00:47:49Z")

</div>

You have a mismatch between the fields defined for the form and the form itself.

In your SignUpForm you specify that there will be Form fields for every field in the model. That includes the Model Fields for password and date\_joined.

The simplest solution is to specify only the fields you need in the form definition.

Ken

---

<div class="post-metadata">

**Author:** ![valenciano8](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/valenciano8/32/1062_2.png) [@valenciano8](https://forum.djangoproject.com/u/valenciano8)\
**Post date:** [June 10, 2020, 1:05am UTC](https://forum.djangoproject.com/t/cant-register-a-user-using-register-function/2881/3 "2020-06-10T01:05:24Z")

</div>

Thank you it worked perfectly !
