Golang Fiber Template Engine HTML: Rendering: Template does not exist
In Golang development, the template engine is a very important part, it can help developers render HTML pages more conveniently. As Golang's lightweight web framework, Fiber also provides its own template engine. In the process of using Fiber, you sometimes encounter the "template does not exist" problem. This problem may be caused by incorrect path settings or the file does not exist. In this article, PHP editor Youzi will analyze the cause of this problem in detail and provide solutions to help you better use the Fiber template engine for HTML rendering.
Question content
On my ubuntu 22.10 digitalocean server, I'm trying to use golang and fiber with the html template engine. Love it so far.
Everything works fine including mysql connection and sending emails. Except for one thing.
I keep getting the error Rendering: Template index does not exist.
File system:
├── /gogo ├── main ├── main.go ├── go.mod ├── go.sum ├── /views └── index.html └── /public └── plaatje.png
My main.go code:
package main import ( "fmt" "log" fiber "github.com/gofiber/fiber/v2" "github.com/gofiber/template/html" ) func main() { // initialize standard go html template engine template_engine := html.new( "./views", ".html", ) // start fiber app := fiber.new(fiber.config{ views: template_engine, }) // add static folder app.static( "/static", // mount address "./public", // path to the file folder ) // endpoint app.get("/", func(c *fiber.ctx) error { // render index template return c.render("index", fiber.map{ "title": "it works", "plat": "almost", }) }) log.fatal(app.listen(":9990")) }
index.html File:
<!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/html; charset=Unicode"> <title>{{.Title}}</title> </head> <body> <h1 id="Title">{{.Title}}</h1> <p>{{.Plat}}</p> <p><img src="/static/imghwm/default1.png" data-src="./static/plaatje.png" class="lazy" alt="Golang Fiber Template Engine HTML: Rendering: Template does not exist" ></p> </body> </html>
When I run it locally on my mac, everything works fine and the templates render as they should.
But on the ubuntu server, everything works fine except the templates and gives the given error:
Rendering: Template index does not exist
I tried changing ownership and permissions in ubuntu: no result. However, this is a bit of a blind spot for me, so this may still be an issue...
I tried modifying the view path (./views, /views, views.etc): no result.
I tried return c.render("index.html", fiber.map{
: No result.
What did I miss?
Solution
Look for the error, it will appear above the fiber information box. For me it looked like this: 2023/03/12 15:40:58 [WARNING]: Unable to load view: template: apply: 9: Function 't' is undefined
. If your template compiles, they will be found using relative paths.
The above is the detailed content of Golang Fiber Template Engine HTML: Rendering: Template does not exist. For more information, please follow other related articles on the PHP Chinese website!

Goimpactsdevelopmentpositivelythroughspeed,efficiency,andsimplicity.1)Speed:Gocompilesquicklyandrunsefficiently,idealforlargeprojects.2)Efficiency:Itscomprehensivestandardlibraryreducesexternaldependencies,enhancingdevelopmentefficiency.3)Simplicity:

C is more suitable for scenarios where direct control of hardware resources and high performance optimization is required, while Golang is more suitable for scenarios where rapid development and high concurrency processing are required. 1.C's advantage lies in its close to hardware characteristics and high optimization capabilities, which are suitable for high-performance needs such as game development. 2.Golang's advantage lies in its concise syntax and natural concurrency support, which is suitable for high concurrency service development.

Golang excels in practical applications and is known for its simplicity, efficiency and concurrency. 1) Concurrent programming is implemented through Goroutines and Channels, 2) Flexible code is written using interfaces and polymorphisms, 3) Simplify network programming with net/http packages, 4) Build efficient concurrent crawlers, 5) Debugging and optimizing through tools and best practices.

The core features of Go include garbage collection, static linking and concurrency support. 1. The concurrency model of Go language realizes efficient concurrent programming through goroutine and channel. 2. Interfaces and polymorphisms are implemented through interface methods, so that different types can be processed in a unified manner. 3. The basic usage demonstrates the efficiency of function definition and call. 4. In advanced usage, slices provide powerful functions of dynamic resizing. 5. Common errors such as race conditions can be detected and resolved through getest-race. 6. Performance optimization Reuse objects through sync.Pool to reduce garbage collection pressure.

Go language performs well in building efficient and scalable systems. Its advantages include: 1. High performance: compiled into machine code, fast running speed; 2. Concurrent programming: simplify multitasking through goroutines and channels; 3. Simplicity: concise syntax, reducing learning and maintenance costs; 4. Cross-platform: supports cross-platform compilation, easy deployment.

Confused about the sorting of SQL query results. In the process of learning SQL, you often encounter some confusing problems. Recently, the author is reading "MICK-SQL Basics"...

The relationship between technology stack convergence and technology selection In software development, the selection and management of technology stacks are a very critical issue. Recently, some readers have proposed...

Golang ...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment