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
相关推荐
Codefengfeng25 分钟前
Python Base环境中加包的方法
开发语言·python
清水白石00826 分钟前
《Python 编程全景解析:从核心精要到测试替身(Test Doubles)五大武器的实战淬炼》
开发语言·python
如若1231 小时前
AutoDL云服务器 NVIDIA 570驱动 EGL渲染修复全记录
运维·服务器·python
甲枫叶1 小时前
【claude】Claude Code正式引入Git Worktree原生支持:Agent全面实现并行独立工作
java·人工智能·git·python·ai编程
清水白石0082 小时前
《Python 编程全景解析:从核心精要到 Hypothesis 属性基测试的边界探索》
开发语言·python
forestsea2 小时前
Spring Cloud Alibaba 2025.1.0.0 正式发布:拥抱 Spring Boot 4.0 与 Java 21+ 的新时代
java·spring boot·后端
IT枫斗者2 小时前
IntelliJ IDEA 2025.3史诗级更新:统一发行版+Spring Boot 4支持,这更新太香了!
java·开发语言·前端·javascript·spring boot·后端·intellij-idea
♡喜欢做梦2 小时前
Spring Boot 日志实战:级别、持久化与 SLF4J 配置全指南
java·spring boot·后端·spring·java-ee·log4j
青衫码上行2 小时前
【项目部署】Spring Boot项目部署的四种方式
java·linux·服务器·spring boot·后端·docker·腾讯云
N***p3652 小时前
Spring Boot项目接收前端参数的11种方式
前端·spring boot·后端