推荐学习书目
› 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 · May 11, 2016 · 3752 views
    This topic created in 3805 days ago, the information mentioned may be changed or developed.

    请问大神们,在做 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 replies  •  2016-05-12 19:41:08 +08:00
    lyhapple
        1
    lyhapple  
       May 11, 2016
    除了 form 当然只能用 ajax 上传了啊,还能玩出啥花样不成
    seanzhao
        2
    seanzhao  
    OP
       May 12, 2016
    @lyhapple 我的意思是在 django 文档里面是使用创建 form 来上传,要结合前端,我是想直接使用 postman 来直接 post 一个 file
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2880 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 15:25 · PVG 23:25 · LAX 08:25 · JFK 11:25
    ♥ Do have faith in what you're doing.