python - Cherrypy issue on updating list -


i have script use cherrypy. script working , html page ok. on html page i'm showing content of 1 list (is exercise learning). working if try put background color based on values in list, starts problem!

            class helloworld(object):                 @cherrypy.expose                 def index(self):                 in range(0, len(li)):                      status_bkg[i]=color_status(li) 

color status little function return 'green' if li[i]==1 'red' if 0. send 2 lists html file in way:

template = loader.load('index.html') title = "exerc 2" ctx = context(title=title, li=li, status=bkg=status_bkg) return template.generate(ctx).render('html', doctype='html') 

now html file have kind of structure:

     ...      <tr py:for="i in len(li)">                 <td class="${status_bkg[i]}">${li[i]}</td>      <tr>            

the 2 classes "green" , "red" ok. first time shows perfectly. when python script start add time time randomly 0 or 1 list, problem raise! 2 lists have same length "li" updated, not status_bkg!

where i'm wrong? tell me if need more code, understand i've simplify little bit.

thanks!

i see typo in code(just might want help):

ctx = context(title=title, li=li, status=bkg=status_bkg) 

needs be:

ctx = context(title=title, li=li, status_bkg=status_bkg) 

i think problem in loop, li never iterating. assuming status_bkg list, change loop to:

for in li:    status_bkg.append(color_status(i)) 

that make sure each element in li had corresponding status_bkg element.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -