2014-10-07 87 views
0

我在学习烧瓶并试图建立一个显示财富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) 

回答

0

我找到了答案,如何让列表进行排序

我改了行的base.html文件来自:

<script> src="{{ url_for('static', filename='sorttable.js', type='text/javascript') }}"</script> 

<script src="{{ config.STATIC_URL }}/static/sorttable.js"></script> 

,似乎做招。

,我肯定会喜欢从别人那里得到的反馈如何这可以普遍提高

0

script标签不正确。您不需要在script<script>)之后立即关闭标签,而是需要首先包含其属性。

<script src="{{ url_for('static', filename='sorttable.js') }}"></script> 

type="text/javascript"是可选的,如果你使用的是HTML5(<!doctype html>),但应包括其他。