Skip to content Skip to sidebar Skip to footer

Adding A Variable In Content Disposition Response File Name-python/django

I am looking to add a a variable into the file name section of my below python code so that the downloaded file's name will change based on a user's input upon download. So instea

Solution 1:

Using str.format:

response['Content-Disposition'] = 'attachment; filename= "{}"'.format(filename)

Using printf-style formatting:

response['Content-Disposition'] = 'attachment; filename= "%s"' % filename

or concatenating strings:

response['Content-Disposition'] = 'attachment; filename= "' + filename + '"'

Post a Comment for "Adding A Variable In Content Disposition Response File Name-python/django"