简体   繁体   English

从 csv 文件调用数据并使用 django 显示到 html 页面

[英]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.

相关问题 Views/ Django 如何从文件 csv 读取文件并在页面上显示信息 - Views/ Django How to read file and show on the page information from file csv 使用Django将CSV文件中的数据添加到数据库 - Adding data from csv file to database using django 如何从上传的 csv 文件中读取数据并使用 django 进行查看? - How to read data from uploaded csv file and view it using django? 如何链接使用Pandas在函数中创建的CSV文件并将其显示在django view / html中? - How do I link a CSV file created in a function using Pandas and show it in my django view/html? 使用Plotly在HTML页面中显示来自熊猫的已处理数据 - Show the processed data from Pandas in HTML page using Plotly 使用django在HTML页面中显示数据库中的数据 - Display data from a database in a HTML page using django 使用 Flask 将 CSV 文件显示为 HTML 页面 - Displaying CSV file as HTML page using Flask Django 如何在同一视图中传递两个不同的查询以从两个不同的 html 页面导出 csv 文件? - Django how to pass two different query in same view for export csv file from two different html page? 如何解析 Django 服务器中 HTML 页面中的 CSV 数据? - How to parse the CSV data in HTML page in Django Server? 将数据从csv文件存储到django中的模型中? - Storing data from csv file into model in django?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM