我在學習燒瓶並試圖建立一個顯示財富500強企業數據的頁面。帶有Javascript的燒瓶HTML模板
我已經得到了正確顯示,現在我試圖能夠通過任何列排序表。它看起來像我需要一些JavaScript我已經保存在我的靜態目錄,但我不上怎麼拉在JavaScript很清楚
問題:
- 我是否有正確的框架?
- 如何正確使用JavaScript?
- 我讀過,我應該把任何腳本標記放在base.html中的頭部,有沒有一段時間我不會那樣做?
- 我不是問我應該是什麼問題?
下面是我的文件結構
-app
--static
*sorttable.js
--templates
*base.html
*companies.html
--run.py
--views.py
--companies.csv
下面是base.html文件
<html>
<head>
<script> src="{{ url_for('static', filename='sorttable.js', type='text/javascript') }}"</script>
{% if title %}
<title>{{ title }} - microblog</title>
{% else %}
<title>Welcome to microblog</title>
{% endif %}
</head>
<body>
<div>Microblog: <a href="/index">Home</a></div>
<div>Login: <a href="/login">Here</a></div>
<hr />
{% block content %}{% endblock %}
</body>
</html>
下面是companies.html
{% extends "base.html" %}
{% block content %}
<table class="sortable">
<table>
<thead>
<tr>
<th> Revenues </th>
<th> Profits </th>
<th> Rank </th>
<th> Company </th>
</tr>
</thead>
{% for keys in companies %}
<tr>
<td> {{ keys.Revenues }} </td>
<td> {{ keys.Profits }} </td>
<td> {{ keys.Rank }} </td>
<td> {{ keys.Standard }} </td>
</tr>
{% endfor %}
<tfoot>
</tfoot>
</table>
{% endblock %}
而且run.py
# encoding: utf-8
from flask import render_template
from app import app
from .forms import LoginForm
@app.route('/companies')
def companies():
import csv
with open('companies.csv','rU') as f:
companies = csv.DictReader(f)
return render_template("companies.html",
title='Home',
companies=companies)