2013-12-12 86 views
3

我有我希望有人能夠幫助...Perl的催化劑 - 無法呈現模板..........沒有找到

我在得到該錯誤的問題開發服務器:

[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 withing我催化劑目錄包含所有我的HTML代碼(eventu盟友它會使用模板工具包,但目前它純粹是html和javscript代碼,我知道這很好)。

我得到了我的瀏覽器應用程序頁面上的錯誤是:

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

我已經用我的HTML.pm查看DEBUG => 'undef'來幫助調試試過,但我似乎並沒有得到任何額外的輸出。

我可能忽略了一些非常明顯的東西,但我不知道它是什麼?

---------------------------- UPDATE --------------- -------------

我剛纔注意到了我的瀏覽器調試屏幕的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屬性? 這是我的問題或完全不相關的原因嗎?

您對我們的幫助,將不勝感激,謝謝

+0

你是root用戶嗎?也許你的web服務器沒有以root身份運行,因此找不到模板。嘗試加載[CWD](http://perldoc.perl.org/Cwd.html),並在控制器中放入諸如'die cwd;'之類的東西,以查看你的東西在哪裏運行。如果它位於另一個用戶的homedir中,則該用戶可能沒有權限讀取'/ root'中的文件。 – simbabque

+0

我在發帖之前檢查了文件權限(我忘了提及)。另外,我只是嘗試以root身份運行開發服務器,但沒有任何區別。我仍然收到相同的錯誤信息。任何其他想法?謝謝 –

+0

把'__PACKAGE __-> config - > {'View :: HTML'}'轉儲到STDERR並確認路徑是你期望的路徑。 – RET

回答

1

它看起來像你的配置不生效。嘗試將您的模板放入root/homescreen/homescreen.tt2而不是root/src/homescreen/homescreen.tt2,Catalyst會找到它。

啊,你在lib/Myproject中有一個錯字。PM:

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

嘗試'View::HTML'代替(注意你有HMTL - 拼寫錯誤)。

+0

偉大的地方,謝謝...我期待它是明顯的東西,但不是那麼明顯......我看過這個我應該發現它的次數 - 再次感謝 –

+1

RET的第一個定理:調試的問題是解決方案是您想到的最後一件事。 :-) – RET