我只是从Flask和Bootstrap开始,对如何将Bootstrap样式应用于Python插入我的模板的表感到困惑。
正常的html是:
<head>
<link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css" media="screen">
</head>
<body>
{{ table }}
</body>
我使用flask_table填充数据,如下所示:
results=db.search(gsearch.name != "") #Search of tinyurl database
mytable=ResultTable(results) #put into columns
return render_template('index.html', form=search, table=mytable)
,然后ResultTable类为:
class ResultTable(Table):
guestid = Col ('ID', show=False) #unique identifier for each entry
name = LinkCol('Name', 'edit', url_kwargs=dict(id='guestid'),attr='name') #clicking on this edits that entry
email = Col('Email') #email address for each entry
所以我以为我会做类似的事情:
<table class="table table-striped table-bordered table-condensed">
{{ table }}
</table>
但这根本不起作用...
任何提示将不胜感激!
答案 0 :(得分:1)
如flask table documention中所述,您可以通过将类添加到table
python对象的classes
属性来向Table
dom添加类。
在您的情况下,将是这样的:
class ResultTable(Table):
classes = ['table', 'table-striped', 'table-bordered', 'table-condensed']
guestid = Col ('ID', show=False) #unique identifier for each entry
name = LinkCol('Name', 'edit', url_kwargs=dict(id='guestid'),attr='name') #clicking on this
email = Col('Email') #email address for each entry