【问题标题】:new user is getting created正在创建新用户
【发布时间】:2020-10-26 08:18:20
【问题描述】:

这是我的models.py

class Profile(models.Model):
idno=models.AutoField(primary_key=True)
name=models.CharField(max_length=30)
email=models.CharField(max_length=40)
choices = (
    ('C', 'C'),
    ('C++', 'C++'),
    ('Java', 'Java'),
    ('Python', 'Python'),
)
intrest = models.CharField(max_length=6, choices=choices)
marks=models.IntegerField(default=0)

这是我的观点,我要求用户选择他们的兴趣

def timeline(request):
intrest=Profile.objects.all()[0].intrest
if intrest =='':
    if request.method=="POST":
        choice=request.POST['choice']
        print(choice)
        profile=Profile(intrest=choice)
        profile.save()

此代码正在创建一个名称和电子邮件为空白的新配置文件,如何将当前信息保存给同一用户?

【问题讨论】:

    标签: django django-models django-views django-forms


    【解决方案1】:

    为兴趣和标记制作单独的模型并使用外键。

    【讨论】:

      【解决方案2】:

      从 POST 中获取这些信息并保存它们:

      choice = request.POST['choice']
      name = request.POST['name']
      email = request.POST['email']
      profile=Profile(intrest=choice, name=name, email=email)
      profile.save()
      

      当然,只要您通过 POST 请求发送它们。

      【讨论】:

      • 我将姓名和电子邮件保存在不同的功能中。我只想用新的兴趣更新我的个人资料
      猜你喜欢
      • 2016-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-04
      • 1970-01-01
      • 2021-04-28
      • 1970-01-01
      • 2015-12-07
      相关资源
      最近更新 更多