【发布时间】:2017-09-14 00:35:51
【问题描述】:
我正在创建一个仪表板,当时我正在根据数据库中的表名创建一个导航栏(这部分没问题)。
在views.py中我有(编辑:已经添加了views.py的其余部分):
from flask import render_template
from app import app
import sqlite3, json
@app.route('/')
@app.route('/index')
def index():
return render_template('index.html',title='Homepage',)
def nav_bar():
connection = sqlite3.connect('C:\\SQLite\\Databases\\testPython.db')
cursor = connection.cursor()
cursor.execute('SELECT NAME FROM sqlite_master WHERE TYPE = \'table\';')
#ORDER BY NAME ASC
#tableNames = cursor.fetchall()
connection.close()
tableNames = json.dumps(cursor.fetchall()).replace("\"], [\"", " ").replace("[[\"","").replace("\"]]","").replace("access_","").split()
return tableNames
我在代码所在的navigation.html中创建了导航-
{% for names in navBar.tableNames %}
<h1>Test</h1>
{% endfor %}
编辑:这是base.html
<html>
<head>
<title>{{ title }} - Dashboard</title>
</head>
<body style="margin: 0; padding: 0;">
<div style="height:7%; background-color: #171819;"><a href="/" style="color: white; vertical-align: middle; text-decoration: none; font-family: Sans-serif; font-size: 20px; position: relative; transform: translateY(-50%); top: 35%; padding-left: 5%">Access Log Dashboard >>></a></div>
<div class="container">
<div class="column-left" style="float: left; width: 15%; background-color: #3c3f42; height: 93%">
{% include 'navigation.html' %}
</div>
<div class="column-centre" style="display: inline-block; width: 80%; color: #3c3f42;">
{% block content %}
{% endblock %}
</div>
</div>
</body>
</html>
如何从 navigation.html 访问 views.py 中的属性?抱歉,如果这是一个新问题,我认为是!
【问题讨论】:
-
你能发给你请添加你的views.py问题吗??
-
@EspoirMurhabazi 添加了额外的views.py,如果你问的是这个?