V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
seanzhao
V2EX  ›  Python

如何使用 django 上传 file,不使用 form?

  •  
  •   seanzhao · 2016-05-11 21:14:44 +08:00 · 2615 次点击
    这是一个创建于 2868 天前的主题,其中的信息可能已经有所发展或是发生改变。

    请问大神们,在做 django 上传 file 的功能,请问想不使用 form 做,按照教程文档建立 models , views,代码简化如下: models.py class Filedata(models.Model): file=models.FileField(upload_to='media')

    views.py def upload_file(request): if request.method=="POST": file_get=request.FILES['file'] create_file=Filedata() create_file.file(file_get.name,content,save=True) return HttpResponse('ok') 但是上传 file 无法成功,请问哪步有问题啊?谢谢大家

    2 条回复    2016-05-12 19:41:08 +08:00
    lyhapple
        1
    lyhapple  
       2016-05-11 22:37:44 +08:00
    除了 form 当然只能用 ajax 上传了啊,还能玩出啥花样不成
    seanzhao
        2
    seanzhao  
    OP
       2016-05-12 19:41:08 +08:00
    @lyhapple 我的意思是在 django 文档里面是使用创建 form 来上传,要结合前端,我是想直接使用 postman 来直接 post 一个 file
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5927 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 06:13 · PVG 14:13 · LAX 23:13 · JFK 02:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.