Django-生成csv文件

定义:

python中生成csv文件:

csv文件下载:

事例:

例子:

urls:

python 复制代码
from django.urls import path
from . import views
urlpatterns = [

    path('test_csv',views.test_csv),
]

views:

python 复制代码
def test_csv(request):
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename="test.csv"'
    writer = csv.writer(response)
    writer.writerow(['Title', 'Content'])
    for i in range(100):
        writer.writerow([i, f'Content {i}'])
    return response
相关推荐
赴前尘5 小时前
golang 查看指定版本库所依赖库的版本
开发语言·后端·golang
web3.08889995 小时前
微店商品详情API实用
python·json·时序数据库
知乎的哥廷根数学学派6 小时前
基于数据驱动的自适应正交小波基优化算法(Python)
开发语言·网络·人工智能·pytorch·python·深度学习·算法
sunfove6 小时前
将 Python 仿真工具部署并嵌入个人博客
开发语言·数据库·python
Learner6 小时前
Python类
开发语言·python
2501_941329726 小时前
门及其组件定位识别_YOLO13-C3k2-PoolingFormer改进模型研究
python
Ancelin安心6 小时前
kali-dirsearch的使用
linux·运维·服务器·python·计算机网络·web安全·网络安全
努力学习的小洋6 小时前
Python训练打卡Day5离散特征的处理-独热编码
人工智能·python·机器学习
Sherry Wangs7 小时前
【ML】机器学习进阶
人工智能·python·机器学习
X1A0RAN7 小时前
python 借助 paramiko 库执行 SSH命令报错:input is not a terminal 解决方式
开发语言·python·ssh