3

我正在查看文档 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).
4

1 回答 1

5

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

文档中你可以得到这个:

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
于 2013-11-18T10:40:33.240 回答