我建立了以下模型:
public class User
{
[Key]
[Required]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required]
[StringLength(50)]
public string UserName { get; set; }
[Required]
public TypeOfProfile ProfileType { get; se
EDIT1:我试着做but刷新来重置所有内容,但这并没有帮助。
EDIT2:我能够创建一个用户并将OtherModel指定为NULL,然后编辑用户以使其他模型成为实际引用。当我在用户创建过程中指定引用时,就会出现此问题。
因此,在我与postgres连接的应用程序中,我试图扩展django提供的名为UserProfile的用户模型。我希望每个用户都与我创建的另一个模型相关联。这是我的密码:
models.py
.
.
.
class OtherModel(models.Model):
# model info
class UserProfile(models.Model):
因此,我已经用django-rest-framework JWT身份验证创建了一个后端,现在,我正在尝试解决这样的问题:当用户手动提供URL时,必须检查用户以前是否登录。
因此,当用户登录时,我将令牌存储到localStorage。我是这样做的:
componentDidMount() {
if (localStorage.getItem('token')) {
// fetch current user
this.props.ctx.toggleLoggedIn()
// this.props.ctx.setUserna
我有点问题。我导入django用户模型,创建新用户,然后尝试获取它的配置文件,所有我得到的是“配置文件匹配查询不存在”。为什么?我只是创建了用户。
下面是我的代码:
from django.contrib.auth.models import User
user = User.objects.create(username="stackoverflow", password="tester1234")
user.get_profile()