2013-10-01 6 views
1

다음은 내가TypeError : '정의되지 않은'개체가 반복 가능하지 않습니까?

<%inherit file="/openerp/controllers/templates/base_dispatch.mako"/> 
<%def name="header()"> 
    <title>${_("Otp")}</title> 
    <script type="text/javascript">alert("OTP PAGE");</script> 
</%def> 
<%def name="content()"> 
    <table width="100%"> 
     <tr><%include file="header.mako"/></tr> 
    </table> 
    </br> 
    <table class="view" cellpadding="0" cellspacing="0" style="padding-top: 10px; border:none;" align="center"> 
     <tr> 
      <td style="padding:35px 10px 5px 35px; width="450" align="center"> 
       <form action="${py.url(target)}" method="post" name="otpform" id="otpform" style="padding-bottom: 5px; min-width: 100px;"> 
        % for key, value in origArgs.items(): 
         <input type="hidden" name="${key}" value="${value}"/> 
        % endfor 
        <input name="otp_action" value="otp" type="hidden"/> 
        <fieldset class="box" style="width:300px"> 
         <legend style="padding: 4px;"> 
          <img src="/openerp/static/images/stock/stock_person.png" alt=""/> 
         </legend> 
         <div class="box2" style="padding: 5px 5px 20px 5px"> 
          <b>Please enter SMS code</b> 
          <table width="" cellspacing="2px" cellpadding="0" style="border:none;"> 

           <tr> 
            <td class="label"><label for="otp">${_("Otp:")}</label></td> 
            <td style="padding: 3px;"><input type="text" id="otp" name="otp" class="db_user_pass" value="${otp}" autofocus="true"/></td> 
           </tr> 
           <tr> 
            <td></td> 
            <td class="db_login_buttons"> 
             <button type="submit" class="static_boxes">${_("Otp")}</button> 
            </td> 
           </tr> 
          </table> 
         </div> 
        </fieldset> 
       </form> 

      </td> 
     </tr> 
    </table> 

    <%include file="footer.mako"/> 
</%def> 

만든 마코 템플릿입니다 그리고 템플릿에 대한 파이썬 파일

import re 
from openobject.controllers import BaseController 
import cherrypy 
from openerp.utils import rpc 
from mako.lookup import TemplateLookup 
from mako.template import Template 
from openobject import tools 
import openobject 
from openobject.tools import expose, url, redirect, validate, error_handler 
import formencode 
import base64 
import time 

class OTP(BaseController): 

    _cp_path = "/openerp/otp" 
    msg = { 
      } 

    def __init__(self, *args, **kwargs): 
     super(OTP, self).__init__(*args, **kwargs) 
     self._msg = {} 

    @expose() 
    def index(self, *args, **kw): 
     print '>>>>>>>>>>>>>>>>>>>>>>>INDEX<<<<<<<<<<<<<<<<<<<<<<<<<<' 
     self.msg = {} 
     target='/' 
     url='socket://localhost:8070' 
     action='otp' 
     info='' 
     info = None 
     message='' 
     origArgs=self.get_orig_args(kw) 
     self.otp_check(target, action, message, origArgs) 

    @expose(template="/openerp/controllers/templates/otp.mako") 
    def otp_check(self, target, action=None, message=None, origArgs={}): 
     print '>>>>>>>>>>>>>>>>>>>>>>>otp_check<<<<<<<<<<<<<<<<<<<<<<<<<<' 
     target='/' 
     url='socket://localhost:8070' 
     action='otp' 
     info='' 
     info = None 
     return dict(target=target, url=url, action=action, message=message, origArgs=origArgs, info=info) 

    def get_orig_args(self,kw): 
     if not kw.get('otp_action'): 
      return kw 

     new_kw = kw.copy() 
     clear_login_fields(new_kw) 
     return new_kw 

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: 

이다 그러나 그것을 실행에 내가 브라우저에서 다음과 같은 오류를 얻고있다.

500 Internal Server Error 

The server encountered an unexpected condition which prevented it from fulfilling the request. 

Traceback (most recent call last): 
    File "/usr/lib/pymodules/python2.6/cherrypy/_cprequest.py", line 606, in respond 
    cherrypy.response.body = self.handler() 
    File "/usr/lib/pymodules/python2.6/cherrypy/_cpdispatch.py", line 25, in __call__ 
    return self.callable(*self.args, **self.kwargs) 
    File "/home/zbeanz/workspace/Sms_authentication/openerp-web-6.0.4/openobject/tools/_expose.py", line 182, in func_wrapper 
    res = func(*args, **kw) 
    File "/home/zbeanz/workspace/Sms_authentication/openerp-web-6.0.4/openobject/controllers/_root.py", line 90, in default 
    return request.handler() 
    File "/usr/lib/pymodules/python2.6/cherrypy/_cpdispatch.py", line 25, in __call__ 
    return self.callable(*self.args, **self.kwargs) 
    File "/home/zbeanz/workspace/Sms_authentication/openerp-web-6.0.4/openobject/tools/_expose.py", line 182, in func_wrapper 
    res = func(*args, **kw) 
    File "/home/zbeanz/workspace/Sms_authentication/openerp-web-6.0.4/addons/openerp/controllers/otp.py", line 83, in index 
    self.otp_check(target, action, message, origArgs) 
    File "/home/zbeanz/workspace/Sms_authentication/openerp-web-6.0.4/openobject/tools/_expose.py", line 222, in func_wrapper 
    return render_template(_template, res).encode("utf-8") 
    File "/home/zbeanz/workspace/Sms_authentication/openerp-web-6.0.4/openobject/tools/_expose.py", line 141, in render_template 
    return utils.NoEscape(template.render_unicode(**kw)) 
    File "/usr/lib/pymodules/python2.6/mako/template.py", line 138, in render_unicode 
    return runtime._render(self, self.callable_, args, data, as_unicode=True) 
    File "/usr/lib/pymodules/python2.6/mako/runtime.py", line 364, in _render 
    _render_context(template, callable_, context, *args, **_kwargs_for_callable(callable_, data)) 
    File "/usr/lib/pymodules/python2.6/mako/runtime.py", line 381, in _render_context 
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs) 
    File "/usr/lib/pymodules/python2.6/mako/runtime.py", line 414, in _exec_template 
    callable_(context, *args, **kwargs) 
    File "_openobject_controllers_templates_base_mako", line 61, in render_body 
    File "/usr/lib/pymodules/python2.6/mako/runtime.py", line 255, in <lambda> 
    return lambda *args, **kwargs:callable_(self.context, *args, **kwargs) 
    File "_openerp_controllers_templates_otp_mako", line 89, in render_content 
TypeError: 'Undefined' object is not iterable 

이 오류의 원인은 무엇입니까?

+0

색인을 생성하기 위해 사용하는 URL을 제공 할 수 있습니까? –

답변

2

오류 설명은 매우 분명합니다.

'Undefined' object is not iterable 

즉, 목록 개체가 있고 mako 파일에서 반복하려고합니다. 그러나 런타임에는 객체에 값이 할당되지 않습니다. 그래서 객체는 정의되지 않습니다. 실행하는 동안 변수 origArgs 값을 가지고있는 경우 귀하의 경우에 당신은 단지 하나 개의 변수를

% for key, value in origArgs.items(): 
    <input type="hidden" name="${key}" value="${value}"/> 
% endfor 

검사를 반복. 그것은 그 오류를 일으키는 일이 아니다 경우, 아래

%if origArgs: 
    % for key, value in origArgs.items(): 
     <input type="hidden" name="${key}" value="${value}"/> 
    % endfor 
%endif 

같은 예외 이런 종류의 처리 "/openerp/controllers/templates/base_dispatch.mako"파일의 반복 가능 객체를 확인하는 것이 좋다. 당신은 그것을 얻을 수 있어야합니다. 여전히 행운이 없다면 아래에 의견을 남겨주세요. 건배!!

관련 문제