1
当我新建一个用户时,我无法登录。它只适用于运行'createsuperuser'命令时设置的用户。Django:无法用新用户登录
我也注意到它不会散列密码。它以明文形式存储。
我曾尝试在管理员和我的用户窗体中创建它,但都不起作用。
的login.html
<form class="m-t" role="form" method="post"
action="{% url 'django.contrib.auth.views.login' %}">{% csrf_token %}
<div class="form-group">
<input id="id_username" name="username" type="text" class="form-control" placeholder="Username"
required="">
</div>
<div class="form-group">
<input id="id_password" name="password" type="password"
class="form-control" placeholder="Password" required="">
</div>
<button type="submit" class="btn btn-primary block full-width m-b">Login</button>
</form>
views.py
class UserProfileCreate(CreateView):
model = UserProfile
form_class = UserProfileForm
queryset = UserProfile.objects.all()
success_url = '/sites/list'
forms.py
class UserProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
exclude = ('creation', 'last_modified')
models.py
class UserProfile(AbstractUser):
company = models.ForeignKey(Company, blank=True, null=True)
site = models.ManyToManyField(Site, blank=True, null=True)
请显示UserProfileForm的代码。 –
已添加UserProfileForm – Mantis
您的用户表单不正确地在数据库中散列密码。请参阅[文档中的示例](https://docs.djangoproject.com/en/1.8/topics/auth/customizing/#a-full-example)以获取更多信息。 – Alasdair