[英]Calling a data from a csv file and show into a html page using django
I am working on a project where I need to import data from a csv file and show an element (suppose the first element, that is first row first column).我正在做一个项目,我需要从 csv 文件中导入数据并显示一个元素(假设第一个元素,即第一行第一列)。 I am importing the data via a form.py file.
我正在通过 form.py 文件导入数据。 There the code is:
那里的代码是:
import pandas as pd
from django.shortcuts import render
def allblogs(request):
input_file = pd.read_csv('file.csv', header= None)
return render(request, 'blog/allblogs.html', {'name': input_file[0][0], 'age': input_file[0][1], 'job':input_file[0][2]})
The html page can be just: html 页面可以是:
{{name}}
But I am seeing nothing (no error as well) in the html output.但我在 html output 中什么也没看到(也没有错误)。 Can anyone help?
任何人都可以帮忙吗?
This will convert your dataframe into dict.这会将您的 dataframe 转换为 dict。
dict1 = input_file.to_dict()
return render(request, 'blog/allblogs.html', dict1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.