如何在Django中使用现有表进行用户登录? [英] How to use an existing table for user login in Django?
本文介绍了如何在Django中使用现有表进行用户登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于表已经存在于数据库中以供登录,因此我无法使用内置的Django模型.我已经使用 inspectdb
将表映射到工作正常的项目,但是登录后如何使用现有的用户模型对视图部分进行身份验证.
Since the tables already exist in the DB for login, I cant use the built-in Django models. I have used inspectdb
to map the tables to the project which s working fine, but with login how do I use the existing user model for authentication the views part.
这是用户"表:
class Credential(models.Model):
username = models.CharField(max_length=255, unique=True)
password = models.CharField(max_length=255)
type = models.ForeignKey('Usertype', models.DO_NOTHING, db_column='type')
class Meta:
managed = False
db_table = 'tb_credential'
verbose_name_plural = "Credentials"
def __str__(self):
return self.username
views.py
def login(request):
form = LoginForm(request.POST)
if form.is_valid():
username = form.cleaned_data.get('username')
password = form.cleaned_data.get('password')
推荐答案
使用.exists()达到了我的目的.
using .exists() served my purpose.
这篇关于如何在Django中使用现有表进行用户登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文