1.关于pycharm中CSS文件的创建
2.创建完成之后,进行测试
1.关于pycharm中CSS文件的创建: https://blog.csdn.net/weixin_45581692/article/details/107495744 2.创建完成之后,进行测试: (1)新建static文件: ![在这里插入图片描述](https://img-blog.csdnimg.cn/02b69282df1a4209963e3d725b509d84.png) 新建的python package文件名一定要为static: (2)新建templates文件: ![在这里插入图片描述](https://img-blog.csdnimg.cn/f355191eb54c48e38f0a5ff8909ebd15.png) 新建的python package文件名一定要为templates: (3)文件的结构: ![在这里插入图片描述](https://img-blog.csdnimg.cn/177dc07368fc45a6854dd837efa9dcc4.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAS2VlcF9UcnlpbmdfR28=,size_18,color_FFFFFF,t_70,g_se,x_16) (4)index3.css:
div {
text-align: center
}
(5)index3.html ![在这里插入图片描述](https://img-blog.csdnimg.cn/24da3fa8cf1346988d7a287521fe635b.png)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="static/index3.css">
<title>Title</title>
<!-- <style>-->
<!-- div{-->
<!-- text-align:center-->
<!-- }-->
<!-- </style>-->
</head>
<body>
<div>
<img src="./static/404.png" width="800px" height="600px">
</div>
</body>
</html>
(6)index3.py文件:
from flask import Flask ,render_template
app=Flask(__name__)
@app.route('/index',methods=['POST','GET'])
def index():
return render_template('index3.html')
if __name__=='__main__':
print('Pycharm')
app.run(debug=True)
(7)运行程序index3.py: ![在这里插入图片描述](https://img-blog.csdnimg.cn/c564ef8b273140698dd46fdbb4502a37.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAS2VlcF9UcnlpbmdfR28=,size_20,color_FFFFFF,t_70,g_se,x_16) 我在程序中的路由路径是: ![在这里插入图片描述](https://img-blog.csdnimg.cn/862c12dbb46e4c7098431cd197cdd3ff.png) 所以自己在写的时候,不像我这样写也可以,名称也不一定要和函数index()相同。
![在这里插入图片描述](https://img-blog.csdnimg.cn/b5aa0d7603394884bb0699e0f2c28d58.png) 我这个程序的目的就是将图片显示在中央,将样式写在了CSS文件中。 ![在这里插入图片描述](https://img-blog.csdnimg.cn/ee7cf3703d8f42f882912b1da922d989.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAS2VlcF9UcnlpbmdfR28=,size_20,color_FFFFFF,t_70,g_se,x_16)
|