Categories
coding tips

django REST framework downloading binary files

When returning a Response from django REST API that contains a binary file, you may encounter an issue:

UnicodeDecodeError: ‘utf-8’ codec can’t decode byte  in position 11: invalid start byte

Categories
coding tips

Handling files upload in django & python 3 without Forms

Sometimes you need to accept a file from a user, and you don’t want to use django Forms. The details come down to how many files you need to accept and do you know the names of the files.

If the file is from your app (or frontend) and you expect it you’ll know the file name, because you named it. But if it is a user selected file the name will be unknown.

Categories
coding tips

Renaming db_column through django migration.

You have a legacy database in your django application, but created models for it. At first, they were unmanaged, but then you realized that it’d be easier for everyone if django handled the whole database. Now you’re left with a bunch of fields having db_column set and are required to change the field name and also the column name in the database.