Flask / Jinja:传递字符串列表时出错

时间:2014-10-02 16:38:16

标签: python flask openshift jinja2

我正在使用以下模板,名为template.html,取自https://realpython.com/blog/python/primer-on-jinja-templating/

<div class="container">
    <p>My string: {{my_string}}</p>
    <p>Value from the list: {{my_list[3]}}</p>
    <p>Loop through the list:</p>
    <ul>
    {% for n in my_list %}
    <li>{{n}}</li>
    {% endfor %}
    </ul>
</div> 

使用提供的Flask视图和代码,输出工作

def template_test():
    return render_template('template.html', my_string="Wheeeee!", my_list=[0,1,2,3,4,5])

我尝试修改它以使用以下代码,我收到错误,页面不显示

  
    

headerList =     ['company','company_text','contact','contact_links','contact_links_text','data_source','date_posted','description','due_date','phone_numbers','title','title_link',' title_link_source','title_link_text']

  
def template_test():
    return render_template('template.html', my_string=headerList[0], my_list=[0,1,2,3,4,5])

我很难过,因为headerList [0]是'str'类型。谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

我从

更改了初始化行
if __name__ == '__main__': dbinit() application.run(debug=True, host="0.0.0.0", port=8888)

if __name__ == '__main__': dbinit() application.run(debug=True, host=os.getenv("OPENSHIFT__IP"), port=os.getenv("OPENSHIFT__PORT")) 

现在可以使用了。谢谢大家