mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 02:31:04 +01:00
view: django: accept struct as template data. Rel to: #1683
This commit is contained in:
parent
b839b5cdb9
commit
3e86301b7a
6
NOTICE
6
NOTICE
|
@ -101,9 +101,9 @@ Revision ID: 5fc50a00491616d5cd0cbce3abd8b699838e25ca
|
|||
toml 3012a1dbe2e4bd1 https://github.com/BurntSushi/toml
|
||||
391d42b32f0577c
|
||||
b7bbc7f005
|
||||
jwt e87a84e0681e206 https://github.com/kataras/jwt
|
||||
f3733932450e25d
|
||||
7747daf215
|
||||
jwt 933b4a74659b074 https://github.com/kataras/jwt
|
||||
00070920d0700b9
|
||||
63fa545d6c
|
||||
uuid cb32006e483f2a2 https://github.com/google/uuid
|
||||
3230e24209cf185
|
||||
c65b477dbf
|
||||
|
|
4
go.mod
4
go.mod
|
@ -11,7 +11,7 @@ require (
|
|||
github.com/dgraph-io/badger/v2 v2.2007.2
|
||||
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385
|
||||
github.com/fatih/structs v1.1.0
|
||||
github.com/flosch/pongo2/v4 v4.0.0
|
||||
github.com/flosch/pongo2/v4 v4.0.1
|
||||
github.com/go-redis/redis/v8 v8.4.0
|
||||
github.com/google/uuid v1.1.2
|
||||
github.com/hashicorp/go-version v1.2.1
|
||||
|
@ -21,7 +21,7 @@ require (
|
|||
github.com/json-iterator/go v1.1.10
|
||||
github.com/kataras/blocks v0.0.4
|
||||
github.com/kataras/golog v0.1.5
|
||||
github.com/kataras/jwt v0.0.6
|
||||
github.com/kataras/jwt v0.0.7
|
||||
github.com/kataras/neffos v0.0.18
|
||||
github.com/kataras/pio v0.0.10
|
||||
github.com/kataras/sitemap v0.0.5
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
|
||||
"github.com/kataras/iris/v12/context"
|
||||
|
||||
"github.com/fatih/structs"
|
||||
"github.com/flosch/pongo2/v4"
|
||||
)
|
||||
|
||||
|
@ -261,15 +262,19 @@ func getPongoContext(templateData interface{}) pongo2.Context {
|
|||
return nil
|
||||
}
|
||||
|
||||
if contextData, isPongoContext := templateData.(pongo2.Context); isPongoContext {
|
||||
return contextData
|
||||
}
|
||||
switch data := templateData.(type) {
|
||||
case pongo2.Context:
|
||||
return data
|
||||
case context.Map:
|
||||
return pongo2.Context(data)
|
||||
default:
|
||||
// if struct, convert it to map[string]interface{}
|
||||
if structs.IsStruct(data) {
|
||||
return pongo2.Context(structs.Map(data))
|
||||
}
|
||||
|
||||
if contextData, isContextViewData := templateData.(context.Map); isContextViewData {
|
||||
return pongo2.Context(contextData)
|
||||
panic("django: template data: should be a map or struct")
|
||||
}
|
||||
|
||||
return templateData.(map[string]interface{})
|
||||
}
|
||||
|
||||
func (s *DjangoEngine) fromCache(relativeName string) *pongo2.Template {
|
||||
|
|
Loading…
Reference in New Issue
Block a user