-2

The server I'm posting ym data to doesn't seem to support format call so I get the folowing error.

Use f-string instead of 'format' call for the functions below.

def write_xlsx_response(self, queryset):
        response = HttpResponse(
            content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        )
        response["Content-Disposition"] = 'attachment; filename="{}.xlsx"'.format(
            self.get_filename()
        )
        export_xlsx_assessment(queryset, response)
        return response

def write_csv_response(self, queryset):
        response = HttpResponse(content_type="application/CSV")
        response["Content-Disposition"] = 'attachment; filename="{}.csv"'.format(
            self.get_filename()
        )
        export_csv_assessment(queryset, response)

        return response

Please how can I convert this to f-string.

Thanks

2
  • 2
    Using an f-string won't work either, if the server is so hopelessly outdated that .format isn't even supported. (That means Python 2.x, since even Python 3.0 has .format) Commented Apr 4, 2024 at 7:11
  • Please post full error traceback. Commented Apr 4, 2024 at 7:40

1 Answer 1

1

the syntax for f-strings and .format is basically the same, you just move the parameters to inside the string and add an f to the front

f'attachment; filename="{self.get_filename()}.csv"'
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.