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

标签 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 属性?这是我的问题的原因还是完全不相关的原因?

最佳答案

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

啊,你的 lib/Myproject.pm 中有错别字:

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

试试 'View::HTML'(注意你有 HMTL - 拼写错误)。

关于html - Perl Catalyst - 无法呈现模板............未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20554569/

相关文章:

javascript - onclick 功能不起作用?查询

perl - 如何在模块中包含排序功能?

ruby-on-rails - 从应用程序布局调用 Controller 操作

css - yii2 中的下拉列表在添加样式属性时失败

html - 与标题菜单重叠的透明 Logo

c# - 如何使用 HTML Agility Pack 清理格式错误的 HTML

javascript - 在中间列悬停时显示 HTML 表侧列

perl - 如何通过CGI.pm包含Meta标签

php - 从随机提供的 XML 文件创建 'description' 文件(也许是 XSD 文件?)

ajax - Rest API - 405 方法不允许