Skip to content
Advertisement

Check file extension in Django FileField

I need to run a different code depending on the extension of the file.

This is a simplified version of the model:

JavaScript

This is the part of the view that I have the problem:

JavaScript

I don’t know how I should write this last condition above. With this version above, I get the error: The ‘python’ engine cannot iterate through this file buffer.

How show I write this condition?

Advertisement

Answer

Use str.endswith

Ex:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement