[英]How to use an existing table for user login in Django?
Since the tables already exist in the DB for login, I cant use the built-in Django models.由于表已经存在于数据库中以供登录,因此我无法使用内置的Django模型。 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.我已经使用inspectdb
将表映射到工作正常的项目,但是登录后如何使用现有的用户模型对视图部分进行身份验证。
This is the User table:这是用户表:
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 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')
Since the tables already exist in the DB for login, I cant use the built-in Django models.由于表已经存在于数据库中以供登录,因此我无法使用内置的Django模型。 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.我已经使用inspectdb
将表映射到工作正常的项目,但是登录后如何使用现有的用户模型对视图部分进行身份验证。
This is the User table:这是用户表:
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 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')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.