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
相关推荐
Black_Rock_br8 分钟前
打通 PyTorch Monarch 与 ROCm:单 Controller 架构的异构算力实战
人工智能·pytorch·python·开源
其实防守也摸鱼15 分钟前
Kimi K3深度测评:长文本之外的真实力
运维·开发语言·网络·人工智能·python·学习·安全
weixin_BYSJ198717 分钟前
springboot3家政平台小程序--附源码00904
java·javascript·spring boot·python·django·flask·php
凤山老林36 分钟前
SpringBoot 3 启用 spring.factories 后如何升级替换原有的 spring.factories ?
spring boot·后端·spring
风痕天际37 分钟前
Pytorch开发教程1——CUDA安装
人工智能·pytorch·python
吃饱了得干活1 小时前
JVM垃圾回收:从新生代到ZGC,从理论到调优
java·jvm·后端
Conan在掘金1 小时前
鸿蒙报错速查:arkts-no-func-expressions 禁用 function 表达式,用了就炸,根因 + 真解法
后端
geovindu1 小时前
python: Breadth First Search Algorithm and Depth First Search Algorithm
开发语言·后端·python·算法·搜索算法
程序员果子1 小时前
CrewAI :当 Agent 学会团队协作
人工智能·git·python·多智能体·agent框架
玉鸯1 小时前
向量检索不是记忆:Agent 记忆的三层进化
python·agent