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
相关推荐
whinc1 小时前
Rust技术周刊 2026年第17周
后端·rust
whinc1 小时前
Rust技术周刊 2026年第18周
后端·rust
whinc1 小时前
Rust技术周刊 2026年第16周
后端·rust
jieyucx2 小时前
Go语言深度解剖:Map扩容机制全解析(增量扩容+等量扩容+渐进式迁移)
开发语言·后端·golang·map·扩容策略
YJlio2 小时前
7.4.5 Windows 11 企业网络连接与网络重置实战:远程访问、本地策略与故障恢复
前端·chrome·windows·python·edge·机器人·django
深耕AI2 小时前
【VS Code避坑指南】点击Python图标提示“没有Python环境”,选择安装uv后这堆输出到底是什么意思?
开发语言·python·uv
第一程序员2 小时前
Rust生命周期管理实战指南:从困惑到掌握
python·github
王码码20352 小时前
Go语言的内存管理:原理与实战
后端·golang·go·接口
程序员威哥2 小时前
实战!Python爬京东商品评论:从采集到情感分析+词云可视化,新手30分钟跑通
开发语言·爬虫·python·scrapy
Lee川2 小时前
打字机是怎么炼成的:Chat 流式输出深度解析
前端·后端·面试