django 基础

web项目:application
session:作用域一次会话的时间
cookie:存储在客户端
request:return render(request,'',参数)一次请求
page:只储存在页面中
清除session三种方法: pop(), clear(), flush()
存储session方式:数据库保存;共享存储来保存;memcached来保存;

文件上传:
forms与model
在html中
<form action="/blog/upload">
   <input type="file" name="uploadFile"/>
   <input type="submit" value="文件上传"/>
</form>
然后再views中写
def upload(request):
    if request.method=="GET":
        return  render(request,"upload.html")
    else:
        username=request.POST.get("username")#接收用户名信息
        myfile =request.FILES.get("uploadFile")#得到文件对象
        # print("myfile--------",myfile.name)
        # print("now===",datetime.now().strftime("%Y%m%d%H%M%S"))#得到当前系统日期
        fileName='static/upload/'+datetime.now().strftime("%Y%m%d%H%M%S")+myfile.name
        #print(fileName)
        dfile=open(fileName,'wb+')#新建一个文件并打开上传
        for row in myfile.chunks():
            dfile.write(row)
        dfile.close()
        return render(request,"upload.html")
配置路径

富文本上传:
需要ueditor插件
然后导入到pychram
在ueditor中更改editor_api路径
baseURL = '/static/ueditor/_src/';
在views中
def uploadd(request):
    if request.method=="GET":
        return  render(request,"upload1.html")
    else:
        username=request.POST.get("uploadFile")#接收用户名信息
        return render(request,"uploadsuccess.html",{"username":username})
在html中
uploadsuccess:
{% autoescape off %}{% comment %}不显示标签的意思{% endcomment %}
{{ username }}<br/>
<img src="{{ imgSrc }}" alt="">
{% endautoescape %}
upload1:
<script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/static/ueditor/_examples/editor_api.js"></script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值