Python html.db文件中一行上的多个链接引用

Python html.db文件中一行上的多个链接引用,python,html,flask,Python,Html,Flask,我在Pythony上有一个flask应用程序,在那里我在html编码的页面上显示.db文件的内容。发生的事情是,我的href所在的列将其放在每一行上,而不是该列中的一行。简言之,我希望每个专栏都能把我带到一个不同的链接。我的问题可能不是很清楚,所以我会提供一个链接到下面的网站以及代码。 这是烧瓶路线: @app.route('/forums') def forums(): conn = sqlite3.connect("/home/Ethankbdca/mysite/forum.db"

我在Pythony上有一个flask应用程序,在那里我在html编码的页面上显示.db文件的内容。发生的事情是,我的href所在的列将其放在每一行上,而不是该列中的一行。简言之,我希望每个专栏都能把我带到一个不同的链接。我的问题可能不是很清楚,所以我会提供一个链接到下面的网站以及代码。

这是烧瓶路线:

@app.route('/forums')
def forums():
    conn = sqlite3.connect("/home/Ethankbdca/mysite/forum.db")
    c = conn.cursor()
    sql = "SELECT Forums, Description, blank FROM Home Order By Forums"
    c.execute(sql)
    allforums = []
    for row in c.fetchall():
        tup = (row[0],row[1],row[2])
        allforums.append(tup)
conn.close()
return render_template('forumhome.html', allforums=allforums)
这是html代码:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" 
href="https://www.w3schools.com/w3css/4/w3.css"/>
<script src="script.js"></script>
</head>
<body>
<h1 align="center">Share Your Code</h1>
<table width="90%">
   {% for x in allforums:  %}
   <tr>
        <td width=5%><a href='/python_forum' >{{ x[0] }}</a></td>
        <td width=50%> {{ x[1] }} </td>
   </tr>
   {% endfor %}
</table><br/>
</body>
</html>

分享你的代码
{所有论坛中x的百分比:%}
{{x[1]}
{%endfor%}


我不确定我是否理解这个问题。使用数据库项的id在另一个路由中检索该项

@app.route('/forum/')
def forum_index():
    conn = sqlite3.connect("/home/Ethankbdca/mysite/forum.db")
    c = conn.cursor()
    sql = "SELECT id, forums, description, blank FROM home ORDER BY forums"
    c.execute(sql)
    records = [(row[0],row[1],row[2]) for row in c.fetchall()]
    conn.close()
    return render_template('forum_index.html', items=records)

@app.route('/forum/<int:item_id>')
def forum_show(item_id):
    conn = sqlite3.connect("/home/Ethankbdca/mysite/forum.db")
    c = conn.cursor()
    c.execute("SELECT * FROM home WHERE id == " + str(item_id))
    record = tuple(c.fetchone())
    conn.close()
    return render_template('forum_show.html', item=record)
@app.route(“/forum/”)
def论坛索引():
conn=sqlite3.connect(“/home/kbdca/mysite/forum.db”)
c=连接光标()
sql=“选择id、论坛、说明、按论坛自主订单为空”
c、 执行(sql)
c.fetchall()中的行的记录=[(行[0],行[1],行[2])]
康涅狄格州关闭
返回呈现模板('forum\u index.html',items=records)
@app.route(“/forum/”)
def论坛展示(项目id):
conn=sqlite3.connect(“/home/kbdca/mysite/forum.db”)
c=连接光标()
c、 执行(“从主目录中选择*,其中id=”+str(项目id))
record=tuple(c.fetchone())
康涅狄格州关闭
返回渲染模板('forum\u show.html',item=record)
layout.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <link rel="stylesheet" href="{{ url_for('static', 'main.css') }}" />
  </head>
  <body>
  {% block content %}{% endblock %}
  </body>
</html>

{%block content%}{%endblock%}
forum_index.html

{% extends 'layout.html' %}
{% block content %}
<h1 align="center">Share Your Code</h1>
<table width="90%">
    {% for item in items:  %}
    <tr>
        <td width=5%><a href="{{ url_for('forum_show', item_id=item[0]) }}" >{{ item[1] }}</a></td>
        <td width=50%>{{ item[2] }}</td>
    </tr>
    {% endfor %}
</table>
{% endblock %}
{%extends'layout.html%}
{%block content%}
分享你的代码
{%用于项中的项:%}
{{项目[2]}
{%endfor%}
{%endblock%}
forum_show.html

{% extends 'layout.html' %}
{% block content %}
    <h1 align="center">Is This Your Code?</h1>
    <div>
        <h4>{{ item[1] }}</h4>
        <code><pre>{{ item[2] }}</pre></code>
    </div>
{% endblock %}
{%extends'layout.html%}
{%block content%}
这是你的密码吗?
{{项目[1]}
{{item[2]}}
{%endblock%}
熟悉CRUD概念,它将帮助您处理应用程序中的订单

如果您使用ORM之类的工具,它会对您有所帮助

将应用程序构造为不同的单独模块。非常有用

你发现你的错误了吗?
玩得开心

打字错误提示:这是一个专栏,不是“勾结”…哦,对不起。我刚看到你的密码。我想,如果你仍然对facebook帐户持开放态度,那么facebook帐户就可以使用。