Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect baseDir for django with embed support #95

Merged
merged 1 commit into from
Mar 4, 2021
Merged

Fix incorrect baseDir for django with embed support #95

merged 1 commit into from
Mar 4, 2021

Conversation

iredmail
Copy link
Contributor

@iredmail iredmail commented Mar 3, 2021

fixes #94

Copy link
Member

@ReneWerner87 ReneWerner87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the pull request we remove the functionality to specify the start folder

we should solve the basic problem you have locally

because before this change the code worked fine for me, so unless we can find a reproducible example where it is obvious that there is a problem with the code (and preferably on every machine), I wouldn't want to make any changes here.

@ReneWerner87
Copy link
Member

okay, i think i misunderstood, unfortunately my test with the test code does not work with the variant, i will do some more tests

@ReneWerner87
Copy link
Member

package main

import (
	"embed"
	"log"
	"net/http"

	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/template/django"
)

//go:embed views/*
var embedDirViews embed.FS
func main() {

	// Create a new engine
	// engine := django.New("./views", ".html")
	engine := django.NewFileSystem(http.FS(embedDirViews), ".html")

	// Or from an embedded system
	// See github.com/gofiber/embed for examples
	// engine := html.NewFileSystem(http.Dir("./views", ".django"))

	// Pass the engine to the Views
	app := fiber.New(fiber.Config{
		Views: engine,
	})

	app.Get("/", func(c *fiber.Ctx) error {
		// Render with and extends
		return c.Render("views/index", fiber.Map{
			"Title": "Hello, World!",
		})
	})

	app.Get("/embed", func(c *fiber.Ctx) error {
		// Render index within layouts/main
		return c.Render("views/embed", fiber.Map{
			"Title": "Hello, World!",
		}, "views/layouts/main2")
	})

	log.Fatal(app.Listen(":3000"))
}

and in the templates
without the "./"

thats working

root cause is this line
https://github.com/flosch/pongo2/blob/master/template_loader.go#L204-L209
when baseDir is "/" then the fullPath looks like "//views/......."

good found, @iredmail

but i have to test it with the other filesystem packages https://docs.gofiber.io/api/middleware/filesystem
If this is also positive, I will approve and merge it.

@ReneWerner87
Copy link
Member

also work with rice:
image
but without the views start dir everywhere

also work with statik:
image
but different pfads, here everything is in the absolute path

also work with fileb0x
image
but with the start directory "views"

looks good i will approve it and ask fenny for a second look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

django: unable to resolve template
2 participants