Perl Catalyst - 无法呈现模板..........未找到

时间:2013-12-12 21:25:18

标签: html perl model-view-controller catalyst template-toolkit

我有一个问题,我希望有人能够提供帮助...

我在开发服务器中遇到的错误:

[info] *** Request 2 (0.000/s) [681] [Thu Dec 12 21:05:39 2013] ***
[debug] Path is "homescreen"
[debug] "GET" request for "homescreen" from "192.168.1.100"
[debug] Rendering template "homescreen/homescreen.tt2"
[error] Couldn't render template "homescreen/homescreen.tt2: file error - homescreen/homescreen.tt2: not found"
[error] Couldn't render template "homescreen/homescreen.tt2: file error - homescreen/homescreen.tt2: not found"
[debug] Response Code: 500; Content-Type: text/html; charset=utf-8; Content-Length: 14312
[info] Request took 0.033915s (29.485/s)
.------------------------------------------------------------+-----------.
| Action                                                     | Time      |
+------------------------------------------------------------+-----------+
| /homescreen                                                | 0.000341s |
| /end                                                       | 0.014055s |
|  -> Myproject::View::HTML->process                         | 0.013049s |
'------------------------------------------------------------+-----------'

我在做什么:

我有以下Controller/Homescreen.pm

package Myproject::Controller::Homescreen;

use strict;
use warnings;
use parent 'Catalyst::Controller';
use Data::Dumper;
use JSON;

__PACKAGE__->config->{namespace} = '';

sub homescreen :Path('/homescreen') :Args(0)  {

        my ( $self, $c ) = @_;
        print STDERR "IN THE HOMESCREEN ACTION\n";


        $c->stash({template => 'homescreen/homescreen.tt2',
                   title => 'Home Screen'
                 });
}

我有以下View/HTML.pm

package Myproject::View::HTML;
use Moose;
use namespace::autoclean;

extends 'Catalyst::View::TT';

__PACKAGE__->config({
    #Changed default TT extension to TT2
    TEMPLATE_EXTENSION => '.tt2',
    render_die => 1,
});

我有以下lib/Myproject.pm

__PACKAGE__->config(
    name => 'Myproject',
    # Disable deprecated behavior needed by old applications
    disable_component_resolution_regex_fallback => 1,
    #enable_catalyst_header => 1, # Send X-Catalyst header
);

__PACKAGE__->config(
        #Configure the view
        'View::HMTL' => {
                #Set the location for TT files
                INCLUDE_PATH => [
                        __PACKAGE__->path_to( 'root', 'src' ),
                ],
        },
);


# Start the application
__PACKAGE__->setup();

然后我的 root/src/homescreen/homescreen.tt2 包含我的Catalyst目录,其中包含我的所有html代码(最终它将使用模板工具包,但目前它纯粹是html和javscript代码,我知道很好。)

我在浏览器的应用程序页面上遇到的错误是:

Couldn't render template "homescreen/homescreen.tt2: file error - homescreen/homescreen.tt2: not found" 

我尝试在HTML.pm View中使用DEBUG => 'undef'来帮助调试,但我似乎没有得到任何额外的输出。

我可能会忽视一些非常明显的东西,但我无法弄清楚它是什么?

----------------------------更新--------------- -------------

我刚刚在浏览器调试屏幕的Config部分注意到以下内容:

配置

  do {
  my $a = {
    "Action::RenderView" => {
      ignore_classes => [
                          "DBIx::Class::ResultSource::Table",
                          "DBIx::Class::ResultSourceHandle",
                          "DateTime",
                        ],
      scrubber_func  => sub { ... },
    },
    "disable_component_resolution_regex_fallback" => 1,
    "home" => "/home/fred/Myproject",
    "name" => "Myproject",
    "Plugin::ConfigLoader" => {},
    "Plugin::Static::Simple" => {
      debug => 1,
      dirs => [],
      ignore_dirs => [],
      ignore_extensions => ["tmpl", "tt", "tt2", "html", "xhtml"],   <---- IS THIS SIGNIFICANT AT ALL?
      include_path => [
        bless({
          dirs => ["", "home", "fred", "Myproject", "root"],
          file_spec_class => undef,
          volume => "",
        }, "Path::Class::Dir"),
      ],
      mime_types => {},
      mime_types_obj => bless({}, "MIME::Types"),
      no_logs => 1,
    },
    "root" => 'fix',
    "stacktrace" => { context => 3, verbose => 0 },
    "static" => 'fix',
    "View::HMTL" => {
      INCLUDE_PATH => [
        bless({
          dirs => ["", "home", "fred", "Myproject", "root", "src"],
          file_spec_class => undef,
          volume => "",
        }, "Path::Class::Dir"),
      ],
    },
  };
  $a->{"root"} = $a->{"Plugin::Static::Simple"}{include_path}[0];
  $a->{"static"} = $a->{"Plugin::Static::Simple"};
  $a;
}

我认为这意味着它忽略了我的模板文件,因为它有.tt2文件扩展名?

但是,我没有在我的Catalyst项目中的任何位置设置此ignore_extensions属性? 这是我的问题的原因还是完全无关的事情?

非常感谢您对此的帮助,谢谢

1 个答案:

答案 0 :(得分:1)

您的配置似乎没有生效。尝试将模板放在root/homescreen/homescreen.tt2而不是root/src/homescreen/homescreen.tt2中,然后Catalyst会找到它。

啊,你的lib / Myproject.pm中有一个拼写错误:

__PACKAGE__->config(
        #Configure the view
        'View::HMTL' => {

请尝试使用'View::HTML'(注意您有HMTL - 拼写错误。)