python - Flask HTML Module access Views.py function's attribute -


i'm creating dashboard @ moment creating navigation bar based on table names in database (this part okay).

in views.py have (edit: have added rest of views.py):

    flask import render_template 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 sqlite_master type = \'table\';')         #order name asc         #tablenames = cursor.fetchall()      connection.close()      tablenames = json.dumps(cursor.fetchall()).replace("\"], [\"", " ").replace("[[\"","").replace("\"]]","").replace("access_","").split()      return tablenames 

i've created navigation in navigation.html code -

{% names in navbar.tablenames %}     <h1>test</h1> {% endfor %} 

edit: here's 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> 

how access attributes in views.py navigation.html? sorry if newby question, assume is!

first need pass tables names return nav_bar function render template :

from flask import render_template app import app  import sqlite3, json  @app.route('/') @app.route('/index') def index():     table_names = nav_bar()     return render_template('base.html',title='homepage',table_names = table_name) def nav_bar():     connection = sqlite3.connect('c:\\sqlite\\databases\\testpython.db')     cursor = connection.cursor()      cursor.execute('select name sqlite_master type = \'table\';')         #order name asc         #tablenames = cursor.fetchall()      connection.close()      table_names = json.dumps(cursor.fetchall()).replace("\"], [\"", " ").replace("[[\"","").replace("\"]]","").replace("access_","").split()      return table_names 

and call template :

{% names in table_names %}     <h1>names</h1> {% endfor %} 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -