提示: 作者被禁止或删除 仅保留发帖内容
本帖最后由 屠龙斩首 于 2023-7-17 13:28 编辑
阳康,首阳,无事可做,今儿早上用了用google的AI,Bard。好像不错哎,还不用象openAI那边小气吧啦,非得用国外手机号注册。Bard你直接用,随便用。
让Bard写了一段代码,用户前端网页输入项目,任务,工时,python后台接受输入,并存储入数据库。看代码基本直接可用,前端还给用了bootstrap。这d对实际工作确实应该会增加效率不少哟。还没时间想着怎么调教好咱们的Bard老兄,咳咳,说到底是自己懒。
以下贴代码,简单肯定是超级简单了点,没时间调教B老兄嘛。
html_bootstrap-----------------------------------------------------------------------------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Project Time Tracking</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body>
<h1 class="text-center">Project Time Tracking</h1>
<form action="/submit" method="post" class="container">
<div class="mb-3">
<label for="employee_name" class="form-label">Employee Name</label>
<input type="text" name="employee_name" id="employee_name" class="form-control form-control-sm" placeholder="Employee Name" style="width: 400px;">
</div>
<div class="mb-3">
<label for="date" class="form-label">Date</label>
<input type="date" name="date" id="date" class="form-control form-control-sm" placeholder="Date" style="width: 400px;">
</div>
<div class="mb-3">
<label for="project" class="form-label">Project</label>
<input type="text" name="project" id="project" class="form-control form-control-sm" placeholder="Project" style="width: 400px;">
</div>
<div class="mb-3">
<label for="task" class="form-label">Task</label>
<input type="text" name="task" id="task" class="form-control form-control-sm" placeholder="Task" style="width: 400px;">
</div>
<div class="mb-3">
<label for="hours" class="form-label">Hours</label>
<input type="number" name="hours" id="hours" class="form-control form-control-sm" placeholder="Hours" step="0.01" style="width: 400px;">
</div>
<input type="submit" value="Submit" class="btn btn-primary">
</form>
</body>
</html>
python_flask---------------------------------------------------------------------------------------------------------------------------------------------------------from flask import Flask, render_template, request
# 创建 Flask 应用程序
app = Flask(__name__)
# 定义路由
@app.route("/")
def index():
return render_template("index.html")
@app.route("/submit", methods=["POST"])
def submit():
# 获取表单数据
employee_name = request.form["employee_name"]
date = request.form["date"]
project = request.form["project"]
task = request.form["task"]
hours = request.form["hours"]
# 连接数据库
connection = mysql.connector.connect(
host='localhost',
user='root',
password='password',
database='mydatabase'
)
# 创建游标对象
cursor = connection.cursor()
# 执行SQL语句
cursor.execute('INSERT INTO time_logs (employee_name, date, project, task,
hours) VALUES (%s, %s, %s, %s, %s)', (employee_name, date, project, task, hours))
# 提交事务
connection.commit()
# 关闭连接
connection.close()
# 重定向到主页
return redirect('/')
if __name__ == "__main__":
app.run(debug=True)