我有一个教师注册页面,其中包含电子邮件,手机号码,密码等字段,该表名为教师。
我也想登录页面。
我在做的是:
在网址页面中添加了以下内容:
url(r'^login/$', auth_views.login, {'template_name': 'login.html'},name='login'),
在settings.py中添加了以下内容:
AUTH_USER_MODEL = 'myapp.Teacher'
添加了login.html:
{% extends "base.html" %}
{% load widget_tweaks %}
{% block body_block %}
{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}
{% if next %}
{% if user.is_authenticated %}
<p>Your account doesn't have access to this page. To proceed,
please login with an account that has access.</p>
{% else %}
<p>Please login to see this page.</p>
{% endif %}
{% endif %}
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="login-panel panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Please Sign In</h3>
</div>
<div class="panel-body">
<form method="post" action="{% url 'login' %}">
{% csrf_token %}
<p class="bs-component">
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>
</p>
<p class="bs-component">
<center>
<input class="btn btn-success btn-sm" type="submit" value="login" />
</center>
</p>
<input type="hidden" name="next" value="{{ next }}" />
</form>
</div>
</div>
</div>
</div>
</div>
{%endblock body_block%}
现在登录页面无效,给我错误:
AttributeError: type object 'Teacher' has no attribute 'REQUIRED_FIELDS'
如何在django中实现自定义登录页面?