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

Template panic "StaticUrlPrefix" not defined #9320

Closed
2 of 7 tasks
bitnom opened this issue Dec 11, 2019 · 8 comments
Closed
2 of 7 tasks

Template panic "StaticUrlPrefix" not defined #9320

bitnom opened this issue Dec 11, 2019 · 8 comments
Labels
type/question Issue needs no code to be fixed, only a description on how to fix it yourself.

Comments

@bitnom
Copy link

bitnom commented Dec 11, 2019

  • Gitea version (or commit ref): 1.10.1
  • Git version: 2.17.1
  • Operating system: Ubuntu 18.04
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

Using the binary distribution, attempting to load templates via the custom directory causes error:

panic: template: repo/migrating:12: function "StaticUrlPrefix" not defined

goroutine 1 [running]:
html/template.Must(...)
	/usr/local/go/src/html/template/template.go:372
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.compile(0x1c80ca8, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000720680, 0x2, 0x2, ...)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:292 +0x4c8
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.(*TemplateSet).Set(0xc001a84090, 0x1c79f4d, 0x7, 0xc00073cff0, 0x0)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:318 +0x86
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.renderHandler(0x1c80ca8, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000720680, 0x2, 0x2, ...)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:385 +0x124
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.Renderer(0xc0005caf10, 0x1, 0x1, 0xc000720660, 0x203000)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:422 +0x11d
code.gitea.io/gitea/modules/templates.HTMLRenderer(0x19db460, 0xc0007469a0)
	/go/src/code.gitea.io/gitea/modules/templates/static.go:118 +0x141
code.gitea.io/gitea/routers/routes.NewMacaron(0xc0000b4f20)
	/go/src/code.gitea.io/gitea/routers/routes/routes.go:169 +0x58f
code.gitea.io/gitea/cmd.runWeb(0xc0000b4f20, 0x0, 0x0)
	/go/src/code.gitea.io/gitea/cmd/web.go:110 +0x78
code.gitea.io/gitea/vendor/github.com/urfave/cli.HandleAction(0x19dcfc0, 0x2e01470, 0xc0000b4f20, 0xc000091740, 0x0)
	/go/src/code.gitea.io/gitea/vendor/github.com/urfave/cli/app.go:490 +0xc8
code.gitea.io/gitea/vendor/github.com/urfave/cli.(*App).Run(0xc0000a9380, 0xc0000a21b0, 0x1, 0x1, 0x0, 0x0)
	/go/src/code.gitea.io/gitea/vendor/github.com/urfave/cli/app.go:264 +0x58c
main.main()
	/go/src/code.gitea.io/gitea/main.go:109 +0x816

Since the binary distro doesn't come with any template files, I cloned the repo and copied the templates directory to /usr/local/bin/custom. Gitea runs fine until I copy these files to custom. I also tried only uploading single tmpl files that I wanted to override with similar error results.

I don't need to build gitea myself in order to use templates, do I? That would be unusual as web templates go.

@mrsdizzie
Copy link
Member

This is because you are using 1.10 release but appear to have copied the templates from master branch. The line that error references was not added until after 1.10:

#7911

You'd need to copy templates from same release you are using, so:

https://github.com/go-gitea/gitea/tree/release/v1.10/templates

@lunny
Copy link
Member

lunny commented Dec 11, 2019

Maybe we could extract template files from a gitea sub command like

gitea template list
gitea template extract templates/repo/migrating

Then it will load the special template file from binary embbed resources to current directory.

@lunny lunny added the type/question Issue needs no code to be fixed, only a description on how to fix it yourself. label Dec 11, 2019
@guillep2k
Copy link
Member

If possible, we should add the URL to the right bunch of templates in the site admin page for easy reference, as well as the current custom dir location. But we'd need at least a mirror in Gitea.com (or do this after migration) in order for the link to be stable.

@guillep2k
Copy link
Member

Maybe we could extract template files from a gitea sub command like

gitea template list
gitea template extract templates/repo/migrating

Then it will load the special template file from binary embbed resources to current directory.

This would be great. Then again, I'd show the proper command somewhere in the info page as an online-help. The reason is that many users use docker instances or other means of automatic installation and are not aware of .ini locations or even the path to Gitea.

@bitnom
Copy link
Author

bitnom commented Dec 11, 2019

After uploading templates from 1.10 branch:

panic: template: repo/migrating:12: function "StaticUrlPrefix" not defined

goroutine 1 [running]:
html/template.Must(...)
	/usr/local/go/src/html/template/template.go:372
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.compile(0x1c80ca8, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc00071e7c0, 0x2, 0x2, ...)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:292 +0x4c8
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.(*TemplateSet).Set(0xc001a5d9b0, 0x1c79f4d, 0x7, 0xc00073aff0, 0x0)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:318 +0x86
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.renderHandler(0x1c80ca8, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc00071e7c0, 0x2, 0x2, ...)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:385 +0x124
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.Renderer(0xc002368f10, 0x1, 0x1, 0xc00071e7a0, 0x203000)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:422 +0x11d
code.gitea.io/gitea/modules/templates.HTMLRenderer(0x19db460, 0xc000216960)
	/go/src/code.gitea.io/gitea/modules/templates/static.go:118 +0x141
code.gitea.io/gitea/routers/routes.NewMacaron(0xc0000dc160)
	/go/src/code.gitea.io/gitea/routers/routes/routes.go:169 +0x58f
code.gitea.io/gitea/cmd.runWeb(0xc0000dc160, 0x0, 0x0)
	/go/src/code.gitea.io/gitea/cmd/web.go:110 +0x78
code.gitea.io/gitea/vendor/github.com/urfave/cli.HandleAction(0x19dcfc0, 0x2e01470, 0xc0000dc160, 0xc0001636e0, 0x0)
	/go/src/code.gitea.io/gitea/vendor/github.com/urfave/cli/app.go:490 +0xc8
code.gitea.io/gitea/vendor/github.com/urfave/cli.(*App).Run(0xc0000a8ea0, 0xc0000a21b0, 0x1, 0x1, 0x0, 0x0)
	/go/src/code.gitea.io/gitea/vendor/github.com/urfave/cli/app.go:264 +0x58c
main.main()
	/go/src/code.gitea.io/gitea/main.go:109 +0x816
panic: template: repo/migrating:12: function "StaticUrlPrefix" not defined

goroutine 1 [running]:
html/template.Must(...)
	/usr/local/go/src/html/template/template.go:372
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.compile(0x1c80ca8, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000178b60, 0x2, 0x2, ...)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:292 +0x4c8
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.(*TemplateSet).Set(0xc001837b90, 0x1c79f4d, 0x7, 0xc000746ff0, 0x0)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:318 +0x86
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.renderHandler(0x1c80ca8, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000178b60, 0x2, 0x2, ...)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:385 +0x124
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.Renderer(0xc00233af10, 0x1, 0x1, 0xc000178b40, 0x203000)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:422 +0x11d
code.gitea.io/gitea/modules/templates.HTMLRenderer(0x19db460, 0xc00003cf50)
	/go/src/code.gitea.io/gitea/modules/templates/static.go:118 +0x141
code.gitea.io/gitea/routers/routes.NewMacaron(0xc0000e2b00)
	/go/src/code.gitea.io/gitea/routers/routes/routes.go:169 +0x58f
code.gitea.io/gitea/cmd.runWeb(0xc0000e2b00, 0x0, 0x0)
	/go/src/code.gitea.io/gitea/cmd/web.go:110 +0x78
code.gitea.io/gitea/vendor/github.com/urfave/cli.HandleAction(0x19dcfc0, 0x2e01470, 0xc0000e2b00, 0xc00016baa0, 0x0)
	/go/src/code.gitea.io/gitea/vendor/github.com/urfave/cli/app.go:490 +0xc8
code.gitea.io/gitea/vendor/github.com/urfave/cli.(*App).Run(0xc0000af040, 0xc0000a81b0, 0x1, 0x1, 0x0, 0x0)
	/go/src/code.gitea.io/gitea/vendor/github.com/urfave/cli/app.go:264 +0x58c
main.main()
	/go/src/code.gitea.io/gitea/main.go:109 +0x816
panic: template: repo/migrating:12: function "StaticUrlPrefix" not defined

goroutine 1 [running]:
html/template.Must(...)
	/usr/local/go/src/html/template/template.go:372
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.compile(0x1c80ca8, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000721160, 0x2, 0x2, ...)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:292 +0x4c8
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.(*TemplateSet).Set(0xc0017db7a0, 0x1c79f4d, 0x7, 0xc00073cff0, 0x0)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:318 +0x86
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.renderHandler(0x1c80ca8, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000721160, 0x2, 0x2, ...)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:385 +0x124
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.Renderer(0xc00236ef10, 0x1, 0x1, 0xc000721120, 0x203000)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:422 +0x11d
code.gitea.io/gitea/modules/templates.HTMLRenderer(0x19db460, 0xc001a783d0)
	/go/src/code.gitea.io/gitea/modules/templates/static.go:118 +0x141
code.gitea.io/gitea/routers/routes.NewMacaron(0xc0000dcdc0)
	/go/src/code.gitea.io/gitea/routers/routes/routes.go:169 +0x58f
code.gitea.io/gitea/cmd.runWeb(0xc0000dcdc0, 0x0, 0x0)
	/go/src/code.gitea.io/gitea/cmd/web.go:110 +0x78
code.gitea.io/gitea/vendor/github.com/urfave/cli.HandleAction(0x19dcfc0, 0x2e01470, 0xc0000dcdc0, 0xc000163bc0, 0x0)
	/go/src/code.gitea.io/gitea/vendor/github.com/urfave/cli/app.go:490 +0xc8
code.gitea.io/gitea/vendor/github.com/urfave/cli.(*App).Run(0xc0000a9520, 0xc0000a21b0, 0x1, 0x1, 0x0, 0x0)
	/go/src/code.gitea.io/gitea/vendor/github.com/urfave/cli/app.go:264 +0x58c
main.main()
	/go/src/code.gitea.io/gitea/main.go:109 +0x816
panic: template: repo/migrating:12: function "StaticUrlPrefix" not defined

goroutine 1 [running]:
html/template.Must(...)
	/usr/local/go/src/html/template/template.go:372
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.compile(0x1c80ca8, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000720580, 0x2, 0x2, ...)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:292 +0x4c8
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.(*TemplateSet).Set(0xc001a8cc00, 0x1c79f4d, 0x7, 0xc00073cff0, 0x0)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:318 +0x86
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.renderHandler(0x1c80ca8, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000720580, 0x2, 0x2, ...)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:385 +0x124
code.gitea.io/gitea/vendor/gitea.com/macaron/macaron.Renderer(0xc00234cf10, 0x1, 0x1, 0xc000720560, 0x203000)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/render.go:422 +0x11d
code.gitea.io/gitea/modules/templates.HTMLRenderer(0x19db460, 0xc00003d080)
	/go/src/code.gitea.io/gitea/modules/templates/static.go:118 +0x141
code.gitea.io/gitea/routers/routes.NewMacaron(0xc0000dcdc0)
	/go/src/code.gitea.io/gitea/routers/routes/routes.go:169 +0x58f
code.gitea.io/gitea/cmd.runWeb(0xc0000dcdc0, 0x0, 0x0)
	/go/src/code.gitea.io/gitea/cmd/web.go:110 +0x78
code.gitea.io/gitea/vendor/github.com/urfave/cli.HandleAction(0x19dcfc0, 0x2e01470, 0xc0000dcdc0, 0xc000163c20, 0x0)
	/go/src/code.gitea.io/gitea/vendor/github.com/urfave/cli/app.go:490 +0xc8
code.gitea.io/gitea/vendor/github.com/urfave/cli.(*App).Run(0xc0000a9380, 0xc0000a21b0, 0x1, 0x1, 0x0, 0x0)
	/go/src/code.gitea.io/gitea/vendor/github.com/urfave/cli/app.go:264 +0x58c
main.main()
	/go/src/code.gitea.io/gitea/main.go:109 +0x816

What am I missing?

@mrsdizzie
Copy link
Member

@TensorTom if it is still that error then it is still using the templates from master branch not 1.10:

You'll see the line it references only exists in the master branch:

<img src="{{StaticUrlPrefix}}/img/loading.png"/>

In 1.10 it uses {{AppSubUrl}}and not StaticUrlPrefix:

<img src="{{AppSubUrl}}/img/loading.png"/>

It isn't clear what you've done, but it would require at least a restart of Gitea if you've replaced the original templates that were downloaded from the master branch. If not, you still have the ones from master branch in use based on that error.

@bitnom
Copy link
Author

bitnom commented Dec 12, 2019

You're right. I didn't realize github doesn't zip whatever branch you're on for download.

borisovano added a commit to borisovano/gitea that referenced this issue Dec 18, 2019
sapk pushed a commit that referenced this issue Dec 18, 2019
* DOCS: add mention of swagger api reference

It's(swagger api link) mentioned vaguely in the FAQ but IMHO missing from API usage page.

* Add warning to avoid template mismatches 

Related to #9320
@sapk
Copy link
Member

sapk commented Dec 18, 2019

I think I can close this issue since it seems resolved. Also @borisovano made a PR to add a warning notice in the docs. Thx @borisovano.
@TensorTom If you need more details feel free to re-open the issue.

@sapk sapk closed this as completed Dec 18, 2019
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/question Issue needs no code to be fixed, only a description on how to fix it yourself.
Projects
None yet
Development

No branches or pull requests

5 participants