擅长:python、mysql、java
<p>获取或创建函数,返回元组:(对象,创建)
-对象是Anon.objects.get_或_create(username1=loggedinuser)的实例
-create是布尔值(如果对象已创建,则为true;如果对象已获取,则为false)</p>
<p>因此,您可以尝试:</p>
<pre><code>loggedinanon, creation= Anon.objects.get_or_create(username1=loggedinuser)
newdoc = Document(docfile = request.FILES['docfile'])
newdoc.save()
loggedinanon.profilePic = newdoc
</code></pre>
<p>我对最后一行有疑问:
loggedinanon.profilePic=newdoc</p>
<p>我认为你应该有更多类似的东西:</p>
<p>objectName=ClassName.update(userName=loggedinanon,默认值={'profilePic':newdoc})</p>
<p>取决于模型的关系。Django教程很长,但确实需要阅读
<a href="https://docs.djangoproject.com/en/3.0/ref/models/querysets/" rel="nofollow noreferrer">https://docs.djangoproject.com/en/3.0/ref/models/querysets/</a></p>