擅长:python、mysql、java
<p>问题的实际原因是DRF试图将<code>user</code>属性添加到<code>request</code>。在文件中简要提到,机制如下:</p>
<blockquote>
<p><strong><a href="http://www.django-rest-framework.org/api-guide/authentication/#how-authentication-is-determined" rel="noreferrer">How authentication is determined</a></strong></p>
<p>If no class authenticates, <code>request.user</code> will be set to an instance of
<code>django.contrib.auth.models.AnonymousUser</code></p>
</blockquote>
<p>因此需要<code>django.contrib.auth</code>应用程序才能正确运行,因此<code>django.contrib.auth</code>需要数据库的工作配置才能执行。</p>
<p>解决此问题的方法是将settings<code>UNAUTHENTICATED_USER</code>属性设置为<code>None</code>。</p>
<p>更改后的配置如下:</p>
<pre class="lang-python prettyprint-override"><code>REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [],
'DEFAULT_PERMISSION_CLASSES': [],
'UNAUTHENTICATED_USER': None,
}
</code></pre>