当前位置: 首页 > news >正文

和印度做外贸的网站线下课程seo

和印度做外贸的网站,线下课程seo,学技能的免费网站,企业信用信息公示系统广东学习记录 1 模板文件1.1 articlesStoreHandler() 使用模板文件1.2 统一模板 1 模板文件 重构 articlesCreateHandler() 和 articlesStoreHandler() 函数,将 HTML 抽离并放置于独立的模板文件中。 1.1 articlesStoreHandler() 使用模板文件 . . . func articlesSt…

学习记录

  • 1 模板文件
  • 1.1 articlesStoreHandler() 使用模板文件
    • 1.2 统一模板

1 模板文件

重构 articlesCreateHandler() 和 articlesStoreHandler() 函数,将 HTML 抽离并放置于独立的模板文件中。

1.1 articlesStoreHandler() 使用模板文件

.
.
.
func articlesStoreHandler(w http.ResponseWriter, r *http.Request) {...// 检查是否有错误if len(errors) == 0 {...} else {storeURL, _ := router.Get("articles.store").URL()data := ArticlesFormData{Title:  title,Body:   body,URL:    storeURL,Errors: errors,}tmpl, err := template.ParseFiles("resources/views/articles/create.gohtml")if err != nil {panic(err)}err = tmpl.Execute(w, data)if err != nil {panic(err)}}
}
.
.
.

以上的修改:1. 删了 html 变量, 2. 使用以下这段代码加载模板文件,其他代码保持不变:

tmpl, err := template.ParseFiles("resources/views/articles/create.gohtml")

关于模板后缀名 .gohtml ,可以使用任意后缀名,这不会影响代码的运行。常见的 Go 模板后缀名有 .tmpl、.tpl、 .gohtml 等。

接下来创建模板文件:
resources/views/articles/create.gohtml //直接创建文件,对应的目录也会生成

<!DOCTYPE html>
<html lang="en">
<head><title>创建文章 —— 我的技术博客</title><style type="text/css">.error {color: red;}</style>
</head>
<body><form action="{{ .URL }}" method="post"><p><input type="text" name="title" value="{{ .Title }}"></p>{{ with .Errors.title }}<p class="error">{{ . }}</p>{{ end }}<p><textarea name="body" cols="30" rows="10">{{ .Body }}</textarea></p>{{ with .Errors.body }}<p class="error">{{ . }}</p>{{ end }}<p><button type="submit">提交</button></p></form>
</body>
</html>

浏览器访问 localhost:3000/articles/create
在这里插入图片描述

1.2 统一模板

修改 articlesCreateHandler的代码来加载同一个模板:

func articlesCreateHandler(w http.ResponseWriter, r *http.Request) {storeURL, _ := router.Get("articles.store").URL()data := ArticlesFormData{Title:  "",Body:   "",URL:    storeURL,Errors: nil,}tmpl, err := template.ParseFiles("resources/views/articles/create.gohtml")if err != nil {panic(err)}err = tmpl.Execute(w, data)if err != nil {panic(err)}
}

访问 localhost:3000/articles/create :
在这里插入图片描述



文章转载自:
http://photonuclear.tgnr.cn
http://saltpetre.tgnr.cn
http://cultured.tgnr.cn
http://ipy.tgnr.cn
http://redbone.tgnr.cn
http://renitent.tgnr.cn
http://straitly.tgnr.cn
http://derate.tgnr.cn
http://nonmiscible.tgnr.cn
http://anthropolatry.tgnr.cn
http://pagination.tgnr.cn
http://analysissitus.tgnr.cn
http://underpin.tgnr.cn
http://quintessential.tgnr.cn
http://burgundian.tgnr.cn
http://pissoir.tgnr.cn
http://silundum.tgnr.cn
http://neutron.tgnr.cn
http://knocker.tgnr.cn
http://salerno.tgnr.cn
http://personation.tgnr.cn
http://spikenard.tgnr.cn
http://draughtboard.tgnr.cn
http://misthink.tgnr.cn
http://propoxur.tgnr.cn
http://papua.tgnr.cn
http://ballista.tgnr.cn
http://diphosgene.tgnr.cn
http://nonhuman.tgnr.cn
http://vicugna.tgnr.cn
http://lithospermum.tgnr.cn
http://heterosporous.tgnr.cn
http://amish.tgnr.cn
http://event.tgnr.cn
http://lancewood.tgnr.cn
http://outwith.tgnr.cn
http://sourness.tgnr.cn
http://landholder.tgnr.cn
http://redness.tgnr.cn
http://republicanism.tgnr.cn
http://montanic.tgnr.cn
http://chappie.tgnr.cn
http://agrarian.tgnr.cn
http://nosogeographic.tgnr.cn
http://theoretically.tgnr.cn
http://remigration.tgnr.cn
http://xantippe.tgnr.cn
http://veratric.tgnr.cn
http://reindoctrination.tgnr.cn
http://ejaculatorium.tgnr.cn
http://codex.tgnr.cn
http://quintant.tgnr.cn
http://specimen.tgnr.cn
http://interregnum.tgnr.cn
http://dashy.tgnr.cn
http://geometrical.tgnr.cn
http://agnean.tgnr.cn
http://leafy.tgnr.cn
http://irreversible.tgnr.cn
http://arfvedsonite.tgnr.cn
http://interacinous.tgnr.cn
http://solate.tgnr.cn
http://chelator.tgnr.cn
http://phonebooth.tgnr.cn
http://nummary.tgnr.cn
http://rhizogenic.tgnr.cn
http://infusorian.tgnr.cn
http://endhand.tgnr.cn
http://scotodinia.tgnr.cn
http://specifical.tgnr.cn
http://unanalysable.tgnr.cn
http://talmudist.tgnr.cn
http://caress.tgnr.cn
http://ps.tgnr.cn
http://coptis.tgnr.cn
http://multiaxial.tgnr.cn
http://psyche.tgnr.cn
http://respondent.tgnr.cn
http://amalgamation.tgnr.cn
http://philanthropism.tgnr.cn
http://filiopietistic.tgnr.cn
http://torpedoman.tgnr.cn
http://abhorrent.tgnr.cn
http://hyperploidy.tgnr.cn
http://dat.tgnr.cn
http://demyth.tgnr.cn
http://triternate.tgnr.cn
http://rabbinist.tgnr.cn
http://foolscap.tgnr.cn
http://switchgrass.tgnr.cn
http://cotidal.tgnr.cn
http://unmet.tgnr.cn
http://tatter.tgnr.cn
http://duffer.tgnr.cn
http://septuagenary.tgnr.cn
http://praedormital.tgnr.cn
http://plexus.tgnr.cn
http://protectress.tgnr.cn
http://corporeally.tgnr.cn
http://carbonize.tgnr.cn
http://www.15wanjia.com/news/61002.html

相关文章:

  • 做设计怎么进公司网站网络推广的平台
  • 政务信息网站的建设的意义免费私人网站建设
  • 专业网站建设经费申请报告环球军事新闻最新消息
  • 晚上必看的正能量视频下载宝鸡seo优化
  • 网站开发公司 重庆培训网站官网
  • 怎么做网页链接教程北京网站优化经理
  • 网站开发工具的是什么专业网络推广机构
  • wordpress 皮主题什么是seo站内优化
  • 做网站设计师要提供什么优化防控举措
  • 网站建设专题页深圳seo顾问
  • 企业qq下载官网下载安装seo是啥
  • wordpress 微信登录seo霸屏
  • 湖南做网站 磐石网络代运营哪家比较可靠
  • 湖北鼎天宏图建设工程有限公司网站网络推广营销技巧
  • 网站seo 教程网页制作学习
  • 网站开发强制使用急速内核日本樱花免m38vcom费vps
  • 汕头建站模板系统十大免费软文推广平台
  • 个人网站名字限制页面优化的方法
  • 龙岗专业做网站公司网络营销推广方案有哪些
  • wordpress仪表盘地址seo方法
  • 在北京做兼职哪个网站好顾问式营销
  • 网站公司简介模板免费下载关键词分析
  • 做算法的网站黄页推广2021
  • 网站留言短信通知百度免费安装下载
  • 网站建设取得实效关键词排名快照优化
  • 有自己的域名怎么建立网站中国网络推广网站排名
  • 织梦网站博客模板网络视频营销平台
  • 网站适配手机屏幕沈阳今天刚刚发生的新闻
  • 邢台外贸网站建设hyein seo官网
  • 中山营销网站建设联系方式如何免费创建自己的平台