简介
在数字化时代,一个简洁、专业的个人简历网站对于求职者来说至关重要。Flask是一个轻量级的Web应用框架,非常适合快速开发个人网站。本文将带您一步步学习如何使用Flask框架搭建一个个性化个人简历网站。
准备工作
在开始之前,请确保您已经安装了Python和pip。接下来,按照以下步骤进行:
- 创建一个新的Python虚拟环境:
python -m venv myenv - 激活虚拟环境:
- Windows:
myenv\Scripts\activate - macOS/Linux:
source myenv/bin/activate
- Windows:
- 安装Flask:
pip install flask
创建项目结构
创建一个名为resume_site的目录,并在其中创建以下文件和文件夹:
resume_site/
│
├── app.py
├── static/
│ ├── css/
│ │ └── style.css
│ └── js/
│ └── script.js
└── templates/
└── index.html
编写应用程序
在app.py文件中,编写以下代码:
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
创建模板
在templates/index.html中,编写以下HTML代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>我的个人简历</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head>
<body>
<header>
<h1>张三的个人简历</h1>
<p>前端开发者</p>
</header>
<section>
<h2>技能</h2>
<ul>
<li>HTML5/CSS3</li>
<li>JavaScript</li>
<li>React</li>
<li>Node.js</li>
</ul>
</section>
<section>
<h2>工作经历</h2>
<article>
<h3>前端开发工程师</h3>
<p>某科技公司,2019年至今</p>
<p>负责公司官网和移动端App的前端开发</p>
</article>
</section>
<footer>
<p>联系我:zhangsan@example.com</p>
</footer>
</body>
</html>
添加样式
在static/css/style.css中,编写以下CSS代码:
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}
header {
background-color: #333;
color: #fff;
padding: 20px;
text-align: center;
}
header h1 {
margin: 0;
}
header p {
font-size: 20px;
}
section {
margin: 20px;
padding: 20px;
background-color: #fff;
}
section h2 {
margin-top: 0;
}
ul {
list-style: none;
padding: 0;
}
ul li {
background-color: #eee;
margin-bottom: 10px;
padding: 10px;
border-radius: 5px;
}
article {
margin-bottom: 20px;
}
footer {
background-color: #333;
color: #fff;
text-align: center;
padding: 10px;
position: absolute;
bottom: 0;
width: 100%;
}
运行应用程序
在终端中,进入resume_site目录并运行以下命令:
python app.py
打开浏览器,访问http://127.0.0.1:5000/,您将看到自己的个人简历网站。
总结
通过以上步骤,您已经成功使用Flask框架搭建了一个个性化的个人简历网站。您可以根据自己的需求,添加更多内容和功能,如在线简历编辑、社交媒体链接等。祝您求职顺利!
