0
我已經創建了擴展用戶模型的員工模型。當我創建一名員工時,我也可以在User.objects中找到相同的用戶,以便我知道它已創建。當我嘗試登錄與用戶的憑據的憑證沒有通過認證(不正確的用戶名或密碼)Django登錄與模型擴展用戶
class Employee(User):
start_date = models.DateField()
@property
def leave_days_remaining(self):
#to calculate
calculated_days=10
return calculated_days
def trial(request):
emp = Employee.objects.create(username='lll', password='pass',
email="[email protected]", first_name='Mokgadi,
last_name='Rasekgala', start_date=datetime.date.today())
found=User.objects.get(username='lll')
print found.email
print found.username
print found.password #Found exists
return render(request, 'leave/trial.html')
{% if form.errors %}
<p>{{ form.errors }}Your username and password didn't match. Please try again.</p>
{% endif %}
<form method="post" action="{% url 'login' %}">
{% csrf_token %}
<p>
<label>Username</label>
<input type="text" name="username">
</p>
<p>
<label>Password</label>
<input type="password" name="password">
</p>
<button type="submit">Login</button>
</form>
您需要使用'create_user',而不是'創建'。或者你需要散列密碼。 – Brobin