<legend id='MDilx'><style id='MDilx'><dir id='MDilx'><q id='MDilx'></q></dir></style></legend>

    <i id='MDilx'><tr id='MDilx'><dt id='MDilx'><q id='MDilx'><span id='MDilx'><b id='MDilx'><form id='MDilx'><ins id='MDilx'></ins><ul id='MDilx'></ul><sub id='MDilx'></sub></form><legend id='MDilx'></legend><bdo id='MDilx'><pre id='MDilx'><center id='MDilx'></center></pre></bdo></b><th id='MDilx'></th></span></q></dt></tr></i><div id='MDilx'><tfoot id='MDilx'></tfoot><dl id='MDilx'><fieldset id='MDilx'></fieldset></dl></div>
      <bdo id='MDilx'></bdo><ul id='MDilx'></ul>

    <small id='MDilx'></small><noframes id='MDilx'>

  • <tfoot id='MDilx'></tfoot>

        “要解压的值太多"例外

        时间:2024-04-21
          <bdo id='956W3'></bdo><ul id='956W3'></ul>

            <tbody id='956W3'></tbody>

          <legend id='956W3'><style id='956W3'><dir id='956W3'><q id='956W3'></q></dir></style></legend>

          <tfoot id='956W3'></tfoot>

            1. <i id='956W3'><tr id='956W3'><dt id='956W3'><q id='956W3'><span id='956W3'><b id='956W3'><form id='956W3'><ins id='956W3'></ins><ul id='956W3'></ul><sub id='956W3'></sub></form><legend id='956W3'></legend><bdo id='956W3'><pre id='956W3'><center id='956W3'></center></pre></bdo></b><th id='956W3'></th></span></q></dt></tr></i><div id='956W3'><tfoot id='956W3'></tfoot><dl id='956W3'><fieldset id='956W3'></fieldset></dl></div>

              <small id='956W3'></small><noframes id='956W3'>

                  本文介绍了“要解压的值太多"例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 Django 开发一个项目,并且我刚刚开始尝试扩展 User 模型以制作用户配置文件.

                  不幸的是,我遇到了一个问题:每次我尝试在模板(例如,user.get_template.lastIP)中获取用户的个人资料时,都会收到以下错误:

                  <上一页>环境:请求方法:GET请求网址:http://localhost:8000/Django 版本:1.1Python版本:2.6.1模板错误:在模板/path/to/base.tpl 中,第 19 行出现错误渲染时遇到异常:解包的值太多19:你好,{{user.username}} ({{ user.get_profile.rep}}).近况如何?登出异常类型:TemplateSyntaxError at/异常值:渲染时捕获异常:解包的值太多

                  关于发生了什么或我做错了什么有什么想法吗?

                  解决方案

                  该异常表示您正在尝试解包一个元组,但元组的值相对于目标变量的数量过多.例如:这项工作,并打印 1,然后 2,然后 3

                  def returnATupleWithThreeValues():返回 (1,2,3)a,b,c = returnATupleWithThreeValues()打印一个打印 b打印 c

                  但这会引发你的错误

                  def returnATupleWithThreeValues():返回 (1,2,3)a,b = returnATupleWithThreeValues()打印一个打印 b

                  加注

                  Traceback(最近一次调用最后一次):文件c.py",第 3 行,在 ?a,b = returnATupleWithThreeValues()ValueError:解包的值太多

                  现在,我不知道为什么会在您的情况下发生这种情况,但也许这个答案会为您指明正确的方向.

                  I'm working on a project in Django and I've just started trying to extend the User model in order to make user profiles.

                  Unfortunately, I've run into a problem: Every time I try to get the user's profile inside of a template (user.get_template.lastIP, for example), I get the following error:

                  Environment:
                  
                  Request Method: GET
                  Request URL: http://localhost:8000/
                  Django Version: 1.1
                  Python Version: 2.6.1
                  
                  Template error:
                  In template /path/to/base.tpl, error at line 19
                     Caught an exception while rendering: too many values to unpack
                  
                  19 :                Hello, {{user.username}} ({{ user.get_profile.rep}}). How's it goin? Logout
                  
                  
                  Exception Type: TemplateSyntaxError at /
                  Exception Value: Caught an exception while rendering: too many values to unpack
                  
                  

                  Any ideas as to what's going on or what I'm doing wrong?

                  解决方案

                  That exception means that you are trying to unpack a tuple, but the tuple has too many values with respect to the number of target variables. For example: this work, and prints 1, then 2, then 3

                  def returnATupleWithThreeValues():
                      return (1,2,3)
                  a,b,c = returnATupleWithThreeValues()
                  print a
                  print b
                  print c
                  

                  But this raises your error

                  def returnATupleWithThreeValues():
                      return (1,2,3)
                  a,b = returnATupleWithThreeValues()
                  print a
                  print b
                  

                  raises

                  Traceback (most recent call last):
                    File "c.py", line 3, in ?
                      a,b = returnATupleWithThreeValues()
                  ValueError: too many values to unpack
                  

                  Now, the reason why this happens in your case, I don't know, but maybe this answer will point you in the right direction.

                  这篇关于“要解压的值太多"例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:STATICFILES_DIR、STATIC_ROOT 和 MEDIA_ROOT 的区别 下一篇:动态添加字段到表单

                  相关文章

                • <small id='Zx4Ui'></small><noframes id='Zx4Ui'>

                    <i id='Zx4Ui'><tr id='Zx4Ui'><dt id='Zx4Ui'><q id='Zx4Ui'><span id='Zx4Ui'><b id='Zx4Ui'><form id='Zx4Ui'><ins id='Zx4Ui'></ins><ul id='Zx4Ui'></ul><sub id='Zx4Ui'></sub></form><legend id='Zx4Ui'></legend><bdo id='Zx4Ui'><pre id='Zx4Ui'><center id='Zx4Ui'></center></pre></bdo></b><th id='Zx4Ui'></th></span></q></dt></tr></i><div id='Zx4Ui'><tfoot id='Zx4Ui'></tfoot><dl id='Zx4Ui'><fieldset id='Zx4Ui'></fieldset></dl></div>

                    <tfoot id='Zx4Ui'></tfoot>
                      <bdo id='Zx4Ui'></bdo><ul id='Zx4Ui'></ul>
                    1. <legend id='Zx4Ui'><style id='Zx4Ui'><dir id='Zx4Ui'><q id='Zx4Ui'></q></dir></style></legend>