Django--05

富文本:发表blog
js  css  html
路径:目录:static/ueditor/ #当前目录下
          url:http://127.0.0.1:8000/static/

文件上传:
1.<form enctype="">
2.<input type="file" name=""/>
3.后台接收文件:request.FILES.get("")
读取文件并保存到服务器的另一个文件中
代码获取项目的 绝对路径+upload/+文件名
4.显示成功的图片时,路径是url


富文本编辑器,上传图片:
导入两个新文件,将uecontroller.py导入APP名的文件中,将config.json导入static文件中。
并更改其中的路径。




在urls.py中导入:
from . import uecontroller
path('richtext',views.richtext),
path('handler',uecontroller.handler),
创建两个新的HTML文件。
richtext.html 和 richSuccess.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文件上传</title>
    <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>
</head>
<body>
<form action="/kake/richtext" method="post" enctype="multipart/form-data">
    {% csrf_token %}
    <!--请输入用户名:<input type="text" name="username"/><br/>
    请选择文件:<input type="file" name="uploadFile"/><br/>
    <input type="submit" value="文件上传"/>-->
    <script type="text/plain" id="uploadFile" name="uploadFile">
            <p>欢迎使用UEditor!</p>
    </script>
    <input type="submit" value="提交"/>
    <script type="text/javascript">
        var editor_a = UE.getEditor('uploadFile',{initialFrameHeight:500,serverUrl:'/kake/handler'});
    </script>
</form>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
{% autoescape off %}
{{ richValue }}
{% endautoescape %}
</body>
</html>
在views.py中:
def richtext(request):
    if request.method=='GET':
        return render(request,'richtext.html')
    else:
        richValue=request.POST.get('uploadFile')
        return render(request,'richSuccess.html',{'richValue':richValue})







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值