在数字化时代,一个精美的个人简历网站不仅可以展示你的才华和技能,还能为你打开更多职业机会的大门。使用Flask框架,你可以快速搭建一个专属的个人展示平台。以下是详细的指南,让你轻松上手。
准备工作
在开始之前,确保你已经安装了以下工具:
- Python 3.x
- Flask
- 一个文本编辑器(如Visual Studio Code或Sublime Text)
创建项目结构
首先,创建一个名为 resume_website 的新文件夹,用于存放你的项目文件。然后,在该文件夹中创建以下文件和目录:
resume_website/
│
├── app.py
├── templates/
│ ├── base.html
│ ├── index.html
│ └── resume.html
└── static/
├── css/
│ └── style.css
└── js/
配置Flask应用
在 app.py 文件中,编写以下代码:
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/resume')
def resume():
return render_template('resume.html')
if __name__ == '__main__':
app.run(debug=True)
这段代码创建了一个名为 app 的 Flask 应用,并定义了两个路由:首页 / 和个人简历页面 /resume。
设计模板
接下来,开始设计你的模板。在 templates 文件夹中,创建 base.html、index.html 和 resume.html 文件。
base.html
在 base.html 文件中,编写以下代码:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>{% block title %}我的简历网站{% endblock %}</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head>
<body>
<header>
<h1>{% block header %}{% endblock %}</h1>
</header>
<main>
{% block content %}{% endblock %}
</main>
<footer>
<p>版权所有 © 2022 我的简历网站</p>
</footer>
</body>
</html>
index.html
在 index.html 文件中,编写以下代码:
{% extends 'base.html' %}
{% block header %}
欢迎来到我的简历网站
{% endblock %}
{% block content %}
<div>
<h2>简介</h2>
<p>这里是简介内容...</p>
</div>
<div>
<h2>技能</h2>
<ul>
<li>Python</li>
<li>Flask</li>
<li>HTML/CSS</li>
</ul>
</div>
{% endblock %}
resume.html
在 resume.html 文件中,编写以下代码:
{% extends 'base.html' %}
{% block header %}
个人简历
{% endblock %}
{% block content %}
<div>
<h2>基本信息</h2>
<p>姓名:张三</p>
<p>年龄:25岁</p>
<p>学历:本科</p>
</div>
<div>
<h2>工作经历</h2>
<ul>
<li>2018年7月 - 2020年6月:某科技公司 Python 开发工程师</li>
<li>2020年7月 - 至今:某创业公司 Flask 项目负责人</li>
</ul>
</div>
{% endblock %}
添加样式和脚本
在 static/css/style.css 文件中,编写以下代码:
body {
font-family: Arial, sans-serif;
line-height: 1.6;
}
header, footer {
background-color: #333;
color: #fff;
text-align: center;
padding: 10px 0;
}
header h1 {
margin: 0;
}
main {
padding: 20px;
}
ul {
list-style: none;
padding: 0;
}
li {
margin-bottom: 10px;
}
运行应用
在终端中,进入 resume_website 文件夹,并运行以下命令:
python app.py
然后,在浏览器中访问 http://127.0.0.1:5000/,你将看到你的个人简历网站已经搭建完成。
总结
通过以上步骤,你已成功使用 Flask 框架搭建了一个个人简历网站。你可以根据自己的需求,进一步完善网站内容和功能。祝你前程似锦!
