分享

python Django

 lib_kun 2017-10-26 发布于重庆
urls.py:
 urlpatterns={url(r'^upload/$')}  主页url(r'^$')
views.py:
def index(request):
  render(request,'index.html')
templates模板文件:
新建一个index.html
enctype="multipart/form-data">
   {%% csrf_token %%} #CSRF 403禁止,带上次的cookie来访问
   #<form action="/upload/" 表示提交后会把数据传到/upload/页面
    结果:选择文件【】上传
一、requests库
if request.method =='POST’:request.FILES('upfile')#如果请求方式为post,则取出文件upfile
md5 = hashlib.md5(file).hexdigest()#取文件md5值解决同名问题
二、pymysql
自动创建数据库:cmd命令 python manage.py makemigrations #生成模型文件
 python manage.py migrate  #创建表
下载文件:file = open('file/{}'.format(md5),'rb').read()
response = HttpResponse(file)
response['content-type'] = "application/octet-stream"return response
三、setting.py
LANGUAGE_CODE = 'zh-hans'#中文

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多