我想在一个简单的网页上显示我的CSV文件的内容,如下所示:
你知道Flask与我有什么关系>
我在Flask上很新,我阅读了Flask的基础教程,但是并没有完全理解它。
没关系,我自己找到了解决方案:
# -*- coding: utf-8 -*-
from flask import Flask
import os
app = Flask (__name__)
#fun var
filepath = os.path.join(os.path.dirname(__file__),'out.csv')
open_read = open(filepath,'r')
page =''
while True:
read_data = open_read.readline()
page += '<p>%s</p>' % read_data
if open_read.readline() == '':
break
@app.route("/")
def index():
return page
if __name__ == "__main__":
app.run()
答案 0 :(得分:0)
您应该使用tablib:
# -*- coding: utf-8 -*-
from flask import Flask
import tablib
import os
app = Flask (__name__)
#fun var
dataset = tablib.Dataset()
with open(os.path.join(os.path.dirname(__file__),'out.csv'))) as f:
dataset.csv = f.read()
@app.route("/")
def index():
return dataset.html
if __name__ == "__main__":
app.run()
更清洁,更简单。
答案 1 :(得分:0)
OP的解决方案(从问题中删除):
没关系,我自己找到了解决方案:
select
*
from
`place_lists`
where
`private` = 0
and exists (
select
*
from
`follows`
where
`place_lists`.`id` = `follows`.`followable_id`
and `created_by_user_id` = 13
and `follows`.`deleted_at` is null
)
and `place_lists`.`deleted_at` is null
order by (
select
`created_at`
from
`follows`
where
`created_by_user_id` = 13
and `followable_id` = `place_lists`.`id`
and `follows`.`deleted_at` is null
) desc