Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django中宾语的意义_Python_Django_Dictionary - Fatal编程技术网

Python Django中宾语的意义

Python Django中宾语的意义,python,django,dictionary,Python,Django,Dictionary,在下面的程序中,行 user=user.objects.get(username=request.POST['username']) 这让我有些困惑。我知道如果我有字典d={word1:definition1,word2:definition2},那么d.get[word1]将输出definition1(word1的id)。因此User.objects是一个字典,因为它的结构是dict.get()。这部分线路有点问题 有人能给我解释一下对象的含义吗 提前谢谢 对象是对模型的引用,模型的唯一目的是

在下面的程序中,行

user=user.objects.get(username=request.POST['username'])

这让我有些困惑。我知道如果我有字典
d={word1:definition1,word2:definition2}
,那么
d.get[word1]
将输出
definition1
word1
id
)。因此
User.objects
是一个字典,因为它的结构是
dict.get()
。这部分线路有点问题

有人能给我解释一下
对象的含义吗


提前谢谢

对象
是对模型的引用,模型的唯一目的是处理数据库查询以从数据库检索所需数据

尽管它有一个方法
get
,该方法与字典的
get
方法同名,但它们在内部对数据的检索位置并不相同

def signup(request):
    if request.method == 'POST':
        if request.POST['password1'] == request.POST['password2']:
            try:
                user = User.objects.get(username=request.POST['username'])
                return render(request, 'accounts/signup.html', {'error':'Username has already been taken'})

            except User.DoesNotExist:
                user = User.objects.create_user(request.POST['username'], password=request.POST['password1'])
                login(request, user)
                return render(request, 'accounts/signup.html')
        else:
            return render(request, 'accounts/signup.html', {'error':'Passwords didn\'t match'})
    else:
        return render(request, 'accounts/signup.html')