A preliminary study on go Revel

Source: Internet
Author: User

1.app/controllers/app.go Controller

Package Controllersimport"Github.com/revel/revel"type Appstruct {    *Revel. Controller}func (c App) Index () Revel. Result {str:="pass a variable to the template to see"    returnC.render (str)}func (c App) Hello (Namestring) Revel. Result {c.validation.required (Name). Message ("name must be filled")    ifc.validation.haserrors () {c.validation.keep () c.flashparams ( )returnc.redirect (App.index)}returnC.render (Name)}

2.app/views/app/index.html template file (the corresponding controller is the Index method of the App.go file)

{{Set."title" "Home"}}{{template"header.html" .}}class="Hero-unit"style="Background-color: #A9F16C"> <divclass="Container"> <divclass="Row"> <divclass="Hero-text"> {{range. Errors}}<p style="Color: #c00">{{. Message}}</p>{{end}}<form action="/app/hello"Method="GET"> <input type="text"Name="Name"Value="{. Flash. Name}}"/> <input type="Submit"Value="Submit"/></form>{{Template"footer.html".}}

app/views/app/hello.html template file (the corresponding controller is the Hello method for the App.go file)

{{set"title""Home""  header.html"  .}} "/"> Back </a>"  footer.html" .}}

Go Revel a preliminary study

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.