简体   繁体   中英

In Python, how do I check that a file is a text file?

The file is uploaded through a Django form. The contents of the file need to be saved into a models.TextField(), for editors to review it before publication.

I am already checking UploadedFile.content_type. I have considered using a regular input field, but as the text is going to be quite long, it would be unwieldy for users to cut and paste.

Google是您的朋友-查看此处

Not all sequences of bytes are valid for ex. UTF-8, maybe you should check this?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM