Django Binary或BLOB模型字段 [英] Django Binary or BLOB model field

查看:456
本文介绍了Django Binary或BLOB模型字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#程序,可在MySQL数据库中插入pdf.现在,我想通过django检索pdf,但是django的models.FileField需要一个"Upload To"参数,这意味着在幕后它实际上将File存储在文件系统中而不是存储在数据库中.有什么方法可以设置Django模型,以便将pdf直接存储在MySQL中?

I have a C# program that inserts a pdf inside a MySQL database. Now I want to retrieve that pdf via django but django's models.FileField needs an "Upload To" parameter which means behind the scenes it actually stores the File on the file system rather than in the database. Is there any way I can set up a django model so that I can store the pdf directly inside MySQL?

致谢

推荐答案

我一直在处理同样的问题,将pdf写入mysql中的mediumblob字段,并通过django检索.我已将mysql字段类型设置为mediumblob,并将django字段类型设置为textfield.我已经使用查询集和httpresponse在浏览器中查看PDF对象(但不是直接在django中).

I have been dealing with this same issue, writing a pdf to a mediumblob field in mysql and retrieving via django. I have set the mysql field type to a mediumblob and the django field type to textfield. I have used a queryset and httpresponse to view the PDF objects in a browser (but not directly in django).

这篇关于Django Binary或BLOB模型字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆