benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf a48d8c5c-19c4-52ed-bb62-f8dea9bb0393

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import csv
import io
from django.http import HttpRequest, FileResponse

def task_func(request, header, csv_data):
    """
    This function generates a CSV file response from a Django HttpRequest. It constructs a CSV
    file using the provided header and CSV data, and sends it back as a Django FileResponse.
    This function is particularly useful in scenarios where you need to provide a downloadable
    CSV file in response to a user request on a Django web application.

    Parameters:
    request (HttpRequest): The incoming Django HttpRequest.
    header (list of str): List of strings representing the header of the CSV file.
    csv_data (list of list of str): List of rows, with each row being a list of strings, to be written into the CSV file.

    Returns:
    FileResponse: A Django FileResponse object containing the CSV data as an attachment.

    Requirements:
    - django.http
    - django.conf
    - csv
    - io

    Examples:
    >>> from django.conf import settings
    >>> if not settings.configured:
    ...     settings.configure()
    >>> request = HttpRequest()
    >>> header = ['id', 'name', 'email']
    >>> csv_data = [['1', 'John Doe', 'john@example.com'], ['2', 'Jane Doe', 'jane@example.com']]
    >>> response = task_func(request, header, csv_data)
    >>> response['Content-Type']
    'text/csv'
    >>> response['Content-Disposition']
    'attachment; filename="data.csv"'
    """

instruct prompt

This function generates a CSV file response from a Django HttpRequest. It constructs a CSV file using the provided header and CSV data, and sends it back as a Django FileResponse. This function is particularly useful in scenarios where you need to provide a downloadable CSV file in response to a user request on a Django web application.
The function should output with:
    FileResponse: A Django FileResponse object containing the CSV data as an attachment.
You should write self-contained code starting with:

Code

import csv
import io
from django.http import HttpRequest, FileResponse
def task_func(request, header, csv_data):

code prompt

Code

import csv
import io
from django.http import HttpRequest, FileResponse
def task_func(request, header, csv_data):

entry point

task_func

libs

  • io
  • csv
  • django

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import