gpt4 book ai didi

perl - mojolicious 路线不起作用

转载 作者:行者123 更新时间:2023-12-01 11:41:37 25 4
gpt4 key购买 nike

我正在查看文档 http://mojolicio.us/perldoc/Mojolicious/Lite

我正在粘贴教程中的示例,但几乎总是收到此错误消息:

找不到页面...还没有!

我试过的最后一个例子是这样的:

use Mojolicious::Lite;

get '/with_layout';

app->start;
__DATA__

@@ with_layout.html.ep
% title 'Green';
% layout 'green';
Hello World!

@@ layouts/green.html.ep
<!DOCTYPE html>
<html>
<head><title><%= title %></title></head>
<body><%= content %></body>
</html>

这是我得到的错误

[Thu Nov 14 03:43:15 2013] [debug] GET "/with_layout".
[Thu Nov 14 03:43:15 2013] [debug] Template "with_layout.html.ep" not found.
[Thu Nov 14 03:43:15 2013] [debug] Template "not_found.development.html.ep" not found.
[Thu Nov 14 03:43:15 2013] [debug] Template "not_found.html.ep" not found.
[Thu Nov 14 03:43:15 2013] [debug] Rendering cached inline template.
[Thu Nov 14 03:43:15 2013] [debug] Rendering cached inline template.
[Thu Nov 14 03:43:15 2013] [debug] 404 Not Found (0.011649s, 85.844/s).

最佳答案

你错过了定义路线的子程序?!

来自 docs你可以得到这个:

use Mojolicious::Lite;

# Route leading to an action that renders a template
get '/with_layout' => sub {
my $self = shift;
$self->render('foo');
};

app->start;
__DATA__

@@ with_layout.html.ep
<!DOCTYPE html>
<html>
<head><title><%= title %></title></head>
<body><%= content %></body>
</html>

更好的是:

get '/with_layout' => sub {
my $self = shift;
$self->render(template => 'with_layout', format => 'html', handler => 'ep');
return;
};

现在是错误:

Template "not_found.development.html.ep" not found.
Template "not_found.html.ep" not found.

您可以在模板目录中创建这些文件

/lite_app.pl
/templates/not_found.development.html.ep
/templates/not_found.html.ep

关于perl - mojolicious 路线不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19972844/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com