Files
pro-go-study/24-httpserver/httpserver/templates/edit.html
yanzuoguang 24f394e79f feat(web): 添加动态模板和表单编辑功能
- 新增 dynamic.go 文件处理 HTML 模板请求
- 实现模板函数 intVal用于字符串到整数转换
- 添加 edit.html 模板支持产品数据编辑- 创建 forms.go 处理表单提交和数据更新
- 新增静态文件服务支持 /static/ 路径访问
- 添加 products.html 模板显示产品列表
- 实现 JSON 数据接口 /json 返回产品列表
- 添加 Bootstrap 样式支持改善界面显示- 实现产品编辑链接和表单提交功能
- 添加输入验证和错误处理机制
2025-10-25 22:01:00 +08:00

44 lines
1.5 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pro go</title>
<link href="/static/bootstrap.min.css" rel="stylesheet"/>
</head>
<body>
{{ $index := intVal (index (index .Request.URL.Query "index") 0) }}
{{ if lt $index (len .Data) }}
{{ with index .Data $index }}
<h3 class="bg-primary text-white text-center p-2 m-2">Product</h3>
<form method="POST" action="/forms/edit">
<div class="form-group">
<label>Index</label>
<input name="index" type="text" value="{{ $index }}" class="form-control" disabled/>
<input name="index" value="{{ $index }}" type="hidden"/>
</div>
<div class="form-group">
<label>Name</label>
<input name="name" type="text" value="{{ .Name }}" class="form-control"/>
</div>
<div class="form-group">
<label>Category</label>
<input name="category" type="text" value="{{ .Category }}" class="form-control"/>
</div>
<div class="form-group">
<label>Price</label>
<input name="price" type="text" value="{{ .Price }}" class="form-control"/>
</div>
<div class="mt-2">
<button type="submit" class="btn btn-primary">Save</button>
<a href="/templates/" class="btn btn-secondary">Cancel</a>
</div>
</form>
{{ end }}
{{ else }}
<h3 class="bg-danger text-white text-center p-2">
No Product At Specified Index
</h3>
{{ end }}
</body>
</html>