簡體   English   中英

Django:使用我的Django模型字段擴展的已創建django用戶

[英]Django: Created django user that are extended with my django model field

這是我的Django模特

class student(User):
    name = models.CharField(max_length = 200)
    phone_no = models.BigIntegerField()
    email_id = models.EmailField()
    version = models.IntegerField()

現在,我想注冊由我的模型字段擴展的用戶。 這是我的學生注冊碼

def registerStudent(request):
    print request.body
    if request.body:
        dataDictionary = json.loads(request.body)
        username = dataDictionary['username']
        first_name = dataDictionary['first_name']
        last_name = dataDictionary['last_name']
        email = dataDictionary['email']
        password = dataDictionary['password']
        password1 = dataDictionary['password1']

        user=User()
        user.username = username
        user.first_name = first_name
        user.last_name = last_name
        user.email = email
        if password == password1:
            user.set_password(password)
        else:
            return HttpResponse(json.dumps([{"validation": "Password does not match", "status": False}]), content_type="application/json")
            user.save()

這里有問題

我想將json作為輸入並使用上述模型字段創建用戶。

我似乎只有在密碼不匹配時才在返回后保存用戶。 將“ user.save()”行向左移動一個標簽。

代碼應為:

    if password == password1:
        user.set_password(password)
        user.save()
    else:
        return HttpResponse(json.dumps([{"validation": "Password does not match"
                                            ,"status": False}])
                            ,content_type="application/json")

現在,如果需要的話,將在password = password1時保存用戶。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM