django 的文件上传
template html(模板文件):
<form enctype="multipart/form-data" method="POST" action="/address/upload/">
<input type="file" name="file" />
<br />
<input type="submit" value="上传文件" />
</form>
a、自定义上传(建议用自定义的)
def index(request):
if request.method == 'POST': obj = request.FILES.get('file')
import os
ppp = os.path.join('static','img',obj.name) f = open(ppp, 'wb')
for chunk in obj.chunks():
f.write(chunk)
f.close()
return HttpResponse(request,'上传成功')
# return render(request, 'file.html')
else:
return render(request,'index.html')
            head_img = request.FILES.get('file')
            print(head_img,"我是file")
            tags = request.POST.get('tags', None)
            # obj = request.FILES.get('file')
            import os
            print(head_img.chunks(),"我是名字")
            Statics = os.path.dirname(os.path.dirname(__file__))
            user_img_file_path = os.path.join(Statics,"Statics",'Down_image',username)
            print(user_img_file_path)
            if not os.path.exists(user_img_file_path):
                os.mkdir(user_img_file_path)
            img_file_path = os.path.join(user_img_file_path,head_img.name)
            f = open(img_file_path, 'wb')
            for chunk in head_img.chunks():
                f.write(chunk)
            f.close()
            return HttpResponse('上传成功')
b、Form上传文件实例
class FileForm(forms.Form):
ExcelFile = forms.FileField()
form
from django.db import models class UploadFile(models.Model):
userid = models.CharField(max_length = )
file = models.FileField(upload_to = './upload/')
date = models.DateTimeField(auto_now_add=True)
models
def UploadFile(request):
uf = AssetForm.FileForm(request.POST,request.FILES)
if uf.is_valid():
upload = models.UploadFile()
upload.userid =
upload.file = uf.cleaned_data['ExcelFile']
upload.save() print upload.file
django 的文件上传的更多相关文章
- python Django之文件上传
		
python Django之文件上传 使用Django框架进行文件上传共分为俩种方式 一.方式一 通过form表单进行文件上传 #=================================== ...
 - day56:django:csrf_token&文件上传
		
目录 1.csrf介绍 2.django实现csrf_token认证 3.django实现文件上传 csrf介绍 什么是csrf? csrf:跨站请求伪造.攻击者通过HTTP请求将数据传送到服务器,从 ...
 - Django(十七)文件上传
		
http://www.cnblogs.com/wupeiqi/articles/5703697.html - 文件上传 - 普通上传 - 自定义页面上传按钮 ...
 - 框架----Django之文件上传
		
一.文件上传 1. 浏览器访问 http://127.0.0.1:8000/f1/ http://127.0.0.1:8000/f2/ 2. urls from django.conf.urls im ...
 - Django的文件上传以及预览、存储
		
思路: 文件上传通过前端的input标签,input设置display:none属性. 内容显示需要让前端通过<img>标签读取图片内容,可以通过<label>标签连接< ...
 - Django实现文件上传功能
		
文件上传 关注公众号"轻松学编程"了解更多. 1.创建上传文件夹 在static文件夹下创建uploads用于存储接收上传的文件 在settings中配置,MEDIA_ROOT=o ...
 - Django普通文件上传
		
前端代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
 - Django处理文件上传File Uploads
		
HttpRequest.FILES 表单上传的文件对象存储在类字典对象request.FILES中,表单格式需为multipart/form-data <form enctype="m ...
 - Django之文件上传
		
一.form表单上传文件 注意: 1.form上需要加enctype="multipart/form-data" 2.form提交的地址需要以/结尾 def form_file(r ...
 
随机推荐
- json_encode详解,转义
			
1.json_encod基本用法:数组转字符串 <?php $arr = array (,,,,); echo json_encode($arr); ?> 以上例程会输出: {,,,,} ...
 - MBProgressHUD+FastCall
			
+ (void)showHudTipStr:(NSString *)tipStr; + (void)showHudTipStr:(NSString *)tipStr{ ) { MBProgressHU ...
 - IOS: 账号,证书 好文整理
			
公钥.私钥.数字证书的概念 http://blog.csdn.net/turui/article/details/2048582 iOS Provisioning Profile(Certificat ...
 - vnc服务器配置实例
			
系统环境为CentOS.RHEL. 临时需要远程连接,参考:http://www.centoscn.com/CentOS/Intermediate/2013/0917/1641.html 一.安装.启 ...
 - 大学站防SQL注入代码(ASP版)
			
方法1: Replace过滤字符 解决方法:查找login.asp下的<from找到下边的类似username=request.Form(”name”) pass=request.Form(”p ...
 - 【转】Flume(NG)架构设计要点及配置实践
			
Flume(NG)架构设计要点及配置实践 Flume NG是一个分布式.可靠.可用的系统,它能够将不同数据源的海量日志数据进行高效收集.聚合.移动,最后存储到一个中心化数据存储系统中.由原来的Fl ...
 - asp.net mvc ClaimsIdentity 授权研究 (还是测试版 有bug)
			
安装 Microsoft.Owin.Host.SystemWeb Identity.Core Microsoft.Owin.Security.Cookies 在是startup.cs做如下修改 p ...
 - solr6.1-----相关配置-详细介绍-启动-全文检索
			
环境准备 jdk1.8.0_60 + apache-tomcat-8.5.4 + solr-6.1.0 进过测试.使用tomcat 7.x 不能正常启动solr .会报错,至于怎么原因,lz 暂时 ...
 - MEAN组合框架搭建教程
			
1,我们先走在官方github里面下载个包文件: git clone https://github.com/linnovate/mean.git (是慢了点) 2,我把这个文件解压后文件名叫mean ...
 - 【转载】Ubuntu 系列安装 Docker
			
系统要求 Docker 支持以下版本的Ubuntu操作系统: Ubuntu Xenial 16.04 (LTS) Ubuntu Wily 15.10 Ubuntu Trusty 14.04 (LTS) ...