Skip to content

Instantly share code, notes, and snippets.

View anshuUnity's full-sized avatar
🎯
Learning

Anshu Pal anshuUnity

🎯
Learning
View GitHub Profile
from your_app import views
from django.urls import path
urlpatterns = [
...
path('csv/', views.user_csv, name='users_csv'),
]
@anshuUnity
anshuUnity / views.py
Last active June 24, 2021 12:31
django-csv
import csv
from django.http import HttpResponse
from django.contrib.auth.models import User
def user_csv(request):
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="users.csv"'
csv_writer = csv.writer(response)