<p>这个问题看起来很常见,所以我想看看是否可以从有限的信息量中复制。</p>
<p>快速搜索在James Bennett的博客<a href="http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/" rel="noreferrer">here</a>中找到了一个条目,其中提到在使用UserProfile扩展用户模型时,settings.py中的一个常见错误可能会导致Django抛出此错误。</p>
<p>引用日志:</p>
<blockquote>
<p>The value of the setting is not "appname.models.modelname", it's just "appname.modelname". The reason is that Django is not using this to do a direct import; instead, it's using an internal model-loading function which only wants the name of the app and the name of the model. Trying to do things like "appname.models.modelname" or "projectname.appname.models.modelname" in the AUTH_PROFILE_MODULE setting will cause Django to blow up with the dreaded "too many values to unpack" error, so make sure you've put "appname.modelname", and nothing else, in the value of AUTH_PROFILE_MODULE.</p>
</blockquote>
<p>如果OP复制了更多的回溯,我希望看到类似下面的内容,我可以通过在AUTH_PROFILE_MODULE设置中添加“models”来复制。</p>
<pre><code>TemplateSyntaxError at /
Caught an exception while rendering: too many values to unpack
Original Traceback (most recent call last):
File "/home/brandon/Development/DJANGO_VERSIONS/Django-1.0/django/template/debug.py", line 71, in render_node
result = node.render(context)
File "/home/brandon/Development/DJANGO_VERSIONS/Django-1.0/django/template/debug.py", line 87, in render
output = force_unicode(self.filter_expression.resolve(context))
File "/home/brandon/Development/DJANGO_VERSIONS/Django-1.0/django/template/__init__.py", line 535, in resolve
obj = self.var.resolve(context)
File "/home/brandon/Development/DJANGO_VERSIONS/Django-1.0/django/template/__init__.py", line 676, in resolve
value = self._resolve_lookup(context)
File "/home/brandon/Development/DJANGO_VERSIONS/Django-1.0/django/template/__init__.py", line 711, in _resolve_lookup
current = current()
File "/home/brandon/Development/DJANGO_VERSIONS/Django-1.0/django/contrib/auth/models.py", line 291, in get_profile
app_label, model_name = settings.AUTH_PROFILE_MODULE.split('.')
ValueError: too many values to unpack
</code></pre>
<p>我认为这是Django仍然有一些导入魔力的少数情况之一,当一个小错误没有抛出预期的异常时,这种魔力往往会导致混淆。</p>
<p>你可以在回溯的末尾看到,我发布的AUTH_PROFILE_模块使用“app name.modelname”表单以外的任何其他表单都会导致“app_label,model_name=settings.AUTH_PROFILE_MODULE.split('.')”行抛出“要解包的值太多”错误。</p>
<p>我99%肯定这是这里遇到的原始问题。</p>