Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Use f-string instead of format call

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks

>Solution :

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"'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading