Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
452478e7
authored
2013-08-01 15:52:33 +0800
by
slene
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'master' of github.com:astaxie/beego
2 parents
6e06720e
6e297267
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
15 deletions
docs/zh/Quickstart.md
template.go
template_test.go
docs/zh/Quickstart.md
View file @
452478e
...
...
@@ -115,7 +115,7 @@
2013/04/13 19:36:17
[
W
]
[
stat views: no such file or directory
]
-
模板
会自动重新加载不
缓存。
-
模板
每次使用都会重新加载,不进行
缓存。
-
如果服务端出错,那么就会在浏览器端显示如下类似的截图:
!
[
](images/dev.png)
...
...
@@ -643,11 +643,11 @@ beego更加人性化的还有一个设计就是支持用户自定义字符串错
## response处理
response可能会有
集中
情况:
response可能会有
几种
情况:
1.
模板输出
模板输出
上面模板介绍里面已经介绍,beego会在执行完相应的Controller里面的对应的Method之后输出到模板。
上面模板介绍里面已经介绍,beego会在执行完相应的Controller里面的对应的Method之后输出到模板。
2.
跳转
...
...
@@ -686,7 +686,7 @@ beego中使用session相当方便,只要在main入口函数中设置如下:
this.TplNames = "index.tpl"
}
上面的例子中我们知道
session有几个方便的方法:
session有几个方便的方法:
-
SetSession(name string, value interface{})
-
GetSession(name string) interface{}
...
...
template.go
View file @
452478e
...
...
@@ -51,19 +51,13 @@ func (self *templatefile) visit(paths string, f os.FileInfo, err error) error {
if
f
==
nil
{
return
err
}
if
f
.
IsDir
()
{
if
f
.
IsDir
()
||
(
f
.
Mode
()
&
os
.
ModeSymlink
)
>
0
{
return
nil
}
else
if
(
f
.
Mode
()
&
os
.
ModeSymlink
)
>
0
{
return
nil
}
else
{
hasExt
:=
false
for
_
,
v
:=
range
BeeTemplateExt
{
if
strings
.
HasSuffix
(
paths
,
v
)
{
hasExt
=
true
break
}
if
!
HasTemplateEXt
(
paths
)
{
return
nil
}
if
hasExt
{
replace
:=
strings
.
NewReplacer
(
"
\\
"
,
"/"
)
a
:=
[]
byte
(
paths
)
a
=
a
[
len
([]
byte
(
self
.
root
))
:
]
...
...
@@ -76,9 +70,16 @@ func (self *templatefile) visit(paths string, f os.FileInfo, err error) error {
self
.
files
[
subdir
]
=
m
}
return
nil
}
func
HasTemplateEXt
(
paths
string
)
bool
{
for
_
,
v
:=
range
BeeTemplateExt
{
if
strings
.
HasSuffix
(
paths
,
"."
+
v
)
{
return
true
}
}
return
nil
return
false
}
func
AddTemplateExt
(
ext
string
)
{
...
...
template_test.go
0 → 100644
View file @
452478e
package
beego
import
(
"os"
"path/filepath"
"testing"
)
func
TestBuildTemplate
(
t
*
testing
.
T
)
{
dir
:=
"_beeTmp"
files
:=
[]
string
{
"1.tpl"
,
"2.html"
,
"3.htmltpl"
,
"4.mystyle"
,
}
if
err
:=
os
.
MkdirAll
(
dir
,
0777
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
for
_
,
name
:=
range
files
{
if
_
,
err
:=
os
.
Create
(
filepath
.
Join
(
dir
,
name
));
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
if
err
:=
BuildTemplate
(
dir
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
BeeTemplates
)
!=
1
{
t
.
Fatalf
(
"should be 1 but got %v"
,
len
(
BeeTemplates
))
}
for
_
,
v
:=
range
BeeTemplates
{
if
len
(
v
.
Templates
())
!=
3
{
t
.
Errorf
(
"should be 3 but got %v"
,
len
(
v
.
Templates
()))
}
}
AddTemplateExt
(
"mystyle"
)
if
err
:=
BuildTemplate
(
dir
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
BeeTemplates
)
!=
1
{
t
.
Fatalf
(
"should be 1 but got %v"
,
len
(
BeeTemplates
))
}
for
_
,
v
:=
range
BeeTemplates
{
if
len
(
v
.
Templates
())
!=
4
{
t
.
Errorf
(
"should be 4 but got %v"
,
len
(
v
.
Templates
()))
}
}
}
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment