I am developing a small website with django and I am using the built-in login view. When I register a standard user and then try to login with the right credentials it shows me the login error "please enter a correct username and password". This problem doesn't occurr with the superusers that I created. The can login with the right credentials without any error message showed.
This is the views.py with my registration view.
from django.shortcuts import redirect, render, get_object_or_404
from django.contrib.auth.models import User
from .forms import UserForm
def register_user(request):
if request.method == "POST":
form = UserForm(request.POST)
if form.is_valid():
user = form.save()
return redirect('user_profile', pk=user.pk)
else:
form = UserForm()
return render(request, 'interport/register_user.html', {'form':form})
The admin.py:
from django.contrib import admin
from django.contrib.auth.models import User
forms.py:
from django import forms
from django.contrib.auth.models import User
class UserForm(forms.ModelForm):
class Meta:
model = User
fields = ('first_name', 'last_name', 'email', 'username', 'password',)
urls.py:
from django.conf.urls import url
from django.contrib.auth import views as auth_views
from . import views
urlpatterns = [
url(r'^accounts/login/$', auth_views.login, name='login'),
url(r'^logout/$', auth_views.logout, {'next_page': '/'}, name='logout'),
url(r'^register_user$', views.register_user, name='register_user'),
url(r'^$', views.home, name='home'),
]
the template for login:
{% extends "interport/base.html" %}
{% block content %}
<div class="container">
<div class="row">
<div class="center col s4 offset-s4 card-panel #fff8e1 amber lighten-5">
<h2>Login</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Login</button>
</form>
</div>
</div>
</div>
{% endblock %}