Question about Perl Dancer Framework
On 09/01/2014 03:56 AM, jean-marie.bourbon@armaturetech.com wrote:
Hi guys!
I recently tried to build my own web application using Dancer but I'm a basic perl developer and I have any interrogations about this framework.
I've first tried to build a login page based on your "navbar_login" example. Once logged in I try to call another page named "test" but it seems to not work (I don't know how to call my page and how Dancer work exactly .. to be honest :-( . ) : I have a login.pm module, main.tt (in views/layout/) index.tt and test.tt in views. Im my login.pm I have declared my routes as following:
get '/index' => sub { template 'index' };
get '/' => sub { template 'login' };
get 'test' => sub { template 'test'; };
So, once logged in I try (and fail) to call my page like this:
elsif($password eq "12345") { #print "ok"; #return '<script> document.location("./views/test.tt");</script>'; #return template 'examples/photo_carousel';# 'index'; #my @animals = qw/dogs cats camels mooses vogons/; return template 'test' => { show => "launching test.tt", }; #session $username => params->{$username}; #redirect params ->{'index'};
#show_ }
Fail also with redirect parameter .. But why and how to call my test page ? I don't understand why it doesn't work, can you explain me please ?
Thanks a lot !
Hi Jean-Marie. Welcome! :) Let's go over the code you showed.
get '/index' => sub { template 'index' };
That will declare a path "/index" for a GET request which will render a template called (if you're using the default templating framework) "index.tt". So far so good.
get '/' => sub { template 'login' };
When someone goes to the main page, render 'login.tt'.
get 'test' => sub { template 'test'; };
You probably want to change this to "get '/test'" instead of "get 'test'". Paths should begin with "/", almost always.
#return '<script> document.location("./views/test.tt
");</script>'; In this case, you want to simply use "redirect" keyword which would do this for you: get '/test' => sub { redirect "/"; # redirect to main page }; In your example, you're trying to redirect to "./views/test.tt" which is a file. HTTP redirects are for *paths*, not *files*. If you want people who go to "/wrong/place" to go to "/test" which renders the right template ("test.tt"), you would write this: get '/wrong/place => sub { redirect '/test' }; get '/test => sub { template 'test'; } Does this help? S. On Mon, Sep 1, 2014 at 6:45 PM, jean-marie.bourbon@armaturetech.com < jean-marie.bourbon@armaturetech.com> wrote:
On 09/01/2014 03:56 AM, jean-marie.bourbon@armaturetech.com wrote:
Hi guys!
I recently tried to build my own web application using Dancer but I'm a basic perl developer and I have any interrogations about this framework.
I've first tried to build a login page based on your "navbar_login" example. Once logged in I try to call another page named "test" but it seems to not work (I don't know how to call my page and how Dancer work exactly .. to be honest :-( . ) : I have a login.pm module, main.tt (in views/layout/) index.tt and test.tt in views. Im my login.pm I have declared my routes as following:
get '/index' => sub { template 'index' };
get '/' => sub { template 'login' };
get 'test' => sub { template 'test'; };
So, once logged in I try (and fail) to call my page like this:
elsif($password eq "12345") { #print "ok"; #return '<script> document.location("./views/test.tt ");</script>'; #return template 'examples/photo_carousel';# 'index'; #my @animals = qw/dogs cats camels mooses vogons/; return template 'test' => { show => "launching test.tt", }; #session $username => params->{$username}; #redirect params ->{'index'};
#show_ }
Fail also with redirect parameter .. But why and how to call my test page ? I don't understand why it doesn't work, can you explain me please ?
Thanks a lot !
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
participants (2)
-
jean-marie.bourbon@armaturetech.com -
Sawyer X