我有一个带有计算机表的SQLite数据库。我在电脑桌上有两排。请求的结果不显示在模板工具包中
我想要得到所有电脑,并在模板工具包模板中显示结果。
这是 Dancer2
控制器代码,它使用 Dancer2::Plugin::Auth::Tiny
和 Dancer2::Plugin::DBIC
get '/listallmachine' => needs login => sub {
my $computerRs = schema('default')->resultset('Computer');
my @computers = $computerRs->all;
template 'listmachine' => {
'title' => 'Liste des machines',
'msg' => get_flash(),
'computers' => \@computers
};
};
而对于模板:
[% FOREACH c IN computers %]
<tr>
<td>[% c.ip %]</td>
<td>[% c.uuid %]</td>
</tr>
[% END %]
配置文件:
# configuration file for development environment
# the logger engine to use
# console: log messages to STDOUT (your console where you started the
# application server)
# file: log message to a file in log/
logger: "console"
# the log level for this environment
# core is the lowest, it shows Dancer2's core log messages as well as yours
# (debug, info, warning and error)
log: "core"
# should Dancer2 consider warnings as critical errors?
warnings: 1
# should Dancer2 show a stacktrace when an 5xx error is caught?
# if set to yes, public/500.html will be ignored and either
# views/500.tt, 'error_template' template, or a default error template will be used.
show_errors: 1
# print the banner
startup_info: 1
plugins:
DBIC:
default:
dsn: dbi:SQLite:dbname=papt.db
该模板不显示任何内容。你有什么想法吗?
您是否检查过“@ computers”中的内容? – Borodin
是的,这是我的电脑数据:请求的结果。如果我不使用模板,它的工作... – Oneill
好的。我认为我的答案(如下)会有所帮助,但似乎还有更多的事情在这里进行。如果您消除了模板工具包并在Perl代码中循环访问数组,那么会发生什么?如果在模板中包含'[%computers.size%]',你会得到什么?或'[%computers.0%]'? –