search
HomeBackend DevelopmentGolangGolang Fiber Template Engine HTML: Rendering: Template does not exist

Golang Fiber 模板引擎 HTML:渲染:模板不存在

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!

Statement
This article is reproduced at:stackoverflow. If there is any infringement, please contact admin@php.cn delete
Golang's Impact: Speed, Efficiency, and SimplicityGolang's Impact: Speed, Efficiency, and SimplicityApr 14, 2025 am 12:11 AM

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

C   and Golang: When Performance is CrucialC and Golang: When Performance is CrucialApr 13, 2025 am 12:11 AM

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 in Action: Real-World Examples and ApplicationsGolang in Action: Real-World Examples and ApplicationsApr 12, 2025 am 12:11 AM

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.

Golang: The Go Programming Language ExplainedGolang: The Go Programming Language ExplainedApr 10, 2025 am 11:18 AM

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.

Golang's Purpose: Building Efficient and Scalable SystemsGolang's Purpose: Building Efficient and Scalable SystemsApr 09, 2025 pm 05:17 PM

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.

Why do the results of ORDER BY statements in SQL sorting sometimes seem random?Why do the results of ORDER BY statements in SQL sorting sometimes seem random?Apr 02, 2025 pm 05:24 PM

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"...

Is technology stack convergence just a process of technology stack selection?Is technology stack convergence just a process of technology stack selection?Apr 02, 2025 pm 05:21 PM

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...

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment