在flask python中管理HTML列表

时间:2016-02-14 19:53:04

标签: python html flask

我用HTML编写了这段代码。

import re

def vowelCounter():

    with open('file.txt', 'r') as inFile:

        content = inFile.read()

        o_count = len(re.findall('o',content))
        e_count = len(re.findall('e',content))
        i_count = len(re.findall('i',content))

        # Note, if you want this to be case-insensitive,
        # then add the addition argument re.I to each findall function

        print("O's: {0}, E's:{1}, I's:{2}".format(o_count,e_count,i_count))

vowelCounter()

工作正常,单击该项目时,相应的链接/页面正常工作。但是当我现在在flask python中打开这个页面时,我无法在HTML代码中打开这里描述的链接。它会抛出一个错误,上面写着" Not Found"。

请帮助我使用此代码或指导我任何来源。

1 个答案:

答案 0 :(得分:1)

在views.py中使用路由:

@app.route('/contact')
def contact():
    return render_template('contact.html')

HTML模板中的url_for:

<li><a href="{{ url_for('contact') }}">Contact</a></li>

'contact'是名称功能。或者只是:

<li><a href="/contact">Contact</a></li>