当前位置:网站首页>FastApi-16-页面美化-1
FastApi-16-页面美化-1
2022-06-10 04:11:00 【Python研究所】
你可能已经发现,前面学习中我们的页面很简单,甚至有点丑陋,那么我们怎么样可以将它做的好看一点呢?答案是使用现成的前端框架。
LayUI
经过小编的初步筛选,我建议使用 LayUI,其口号为经典模块化前端框架,有返璞归真、双面体验、星辰大海的特点。



使用 LayUI
首先引入 LayUI 的 CDN
在我们的文件上传页面中的 head 部分引入 LayUI 的 CDN 资源。
<script src="https://www.layuicdn.com/auto/layui.js" v="2.5.6" e="layui"></script>
<link rel="stylesheet" href="https://www.layuicdn.com/layui-v2.5.6/css/layui.css">
修改文件上传按钮
LayUi 为我们提供了开箱即用的文件上传功能。
怎么样,看起来是不是还不错。
将之前的 form 表单修改为如下:
<form action="/upfile1/" method="POST" enctype="multipart/form-data">
<button type="button" class="layui-btn" id="up_function" name='upload_list'>
<i class="layui-icon"></i>上传文件
</button>
<button type="submit" class="layui-btn">点击显示文件信息</button>
</form>
你会发现,你使用了 LayUI 的 layui-btn 样式。同时在选择文件的按钮上融入了文件上传的 ico。
因为
layui上传文件的操作是由layui的upload模块触发的,所以在上面的form表单中的name='upload_list'和action='/upfile1/'已经失效,需要在layui的upload对象中重新定义。
定义 LayUI 的 upload 对象
<script>
var upload = layui.upload;
//执行实例
var uploadInst = upload.render({
elem: '#up_function' //绑定元素
,url: '/upfile1/' //上传接口
,accept: 'file' //限制上传文件类型
,field: 'upload_list'
,done: function(res){
//上传完毕回调
}
,error: function(){
//请求异常回调
}
});
});
</script>
以上,因为 LayUI 上文件上传默认是异常自动上传的,当我们选择了文件,文件就已经被 layui 上传了,所以我们的 submit 按钮已经没用了。并且,从上面的代码中我们可以看到,当文件上传完成后,并没有做任何操作。如果需要展示新的页面就需要在 done 方法中定义。
页面效果
下一篇我们将介绍,怎么手动上传以及文件预览等功能。
完
往期推荐
点亮在看!
边栏推荐
- [深入研究4G/5G/6G专题-26]: 5G NR开机流程4.4 - RRC连接应答消息MSG4(RRCSetup授权)的调度与消息内容详解
- [science and technology specialty-3]: how many students with science and technology specialty know about the senior high school entrance examination
- CVPR 2022 | indirect lighting modeling in inverse rendering
- Using VBA's WebBrowser control to realize single sign on (SSO) in Excel
- [learn FPGA programming from scratch -16]: quick start chapter - operation steps 2-4- basic syntax of Verilog HDL language description language (both software programmers and hardware engineers can un
- Pytorch CPU/GPU 安装方法。
- 4-mirror address
- Final examination paper 2 of the first postgraduate course in Dialectics of nature
- Lit (I): create components
- 从当前文件夹打开 VS Code
猜你喜欢

Why do SQL statements use indexes but still slow queries?

外观设计产品用途

Design product use

3- programming language -- golang website learning

3-编程语言--golang网址学习

Use 80% of the charts to meet daily work, and use the remaining 20% of the charts to build core competitiveness!

Leetcode weekly buckle race 296

How to write Scala code in idea

MySQL learning
![[image detection - edge detection] image edge extraction based on PCNN with matlab code](/img/1f/ac7e2da5cba47b41300b7dd790de7b.png)
[image detection - edge detection] image edge extraction based on PCNN with matlab code
随机推荐
MySQL - data type
idea中怎样关联查看Scala源代码
[image detection - edge detection] image edge extraction based on PCNN with matlab code
Source code encryption software type analysis
golang学习之四:闭包、defer
Pytoch cpu/gpu installation method.
golang学习之六:中的文件操作
What do you usually ask about "ALI / byte" automation test interview questions in large factories, as well as the skills and answers
Fleeing Beijing, Shanghai and Guangzhou at the age of 35, and giving away food when unemployed at the age of 40, the "dignity" of middle-aged people lies in investing in themselves
阿里云首次年度盈利,国内云厂商何时迎来集体回报期?
Encrypting CEPH RBD using luks2
MySQL——安装
What is 3A game?
SSTI (template injection) - (8)
[science and technology specialty-3]: how many students with science and technology specialty know about the senior high school entrance examination
[in depth study of 4g/5g/6g topic -24]: 5g NR startup process 4.2 - scheduling process and uplink synchronization of random access response message msg2, and time advance TA are sent through PDSCH cha
MySQL - constraints
[激光器原理与应用-1]:什么是激光器以及激光器的常见应用
Final examination paper 2 of the first postgraduate course in Dialectics of nature
【毕业设计2】基于STM32的智能抽油烟机系统