[Dancer-users] Template run time error.
Carlos Ivan Sosa
gnusosa at gnusosa.net
Sat Jan 15 01:42:21 CET 2011
Hello I just started using Dancer, and I find it quite useful for mid-size
webpages.
I'm playing with it, but while trying out something like the blog engine in
Perl Dancer Advent Calendar,
I came to a problem of my own.
I'm using damog's Dancer::Template::Haml wich is a wrapper for Text::Haml
I will post my app.pm:
---------------------------------------------------------------------------------------------------------------------------------------
package log;
use Dancer ':syntax';
use DBI;
our $VERSION = '0.1';
my $database = "lib/database.db";
sub connect_db {
my $dbh = DBI->connect("dbi:SQLite:dbname=".$database) or
die $DBI::errstr;
return $dbh;
}
sub exec_sql {
my $db = connect_db();
my $sql = "select id, url, title, text from entries where url
='".$_[0]."'";
my $sth = $db->prepare($sql) or die $db->errstr;
$sth->execute or die $sth->errstr;
return $sth->fetchrow_hashref();
$sth->finish();
}
get '/' => sub {
layout 'index';
my $entry = "hola";
my $field = exec_sql($entry);
template 'index' => {
'url' => $field->{url},
'title' => $field->{title},
'text' => $field->{text},
};
};
get '/archive' => sub {
return "This is the archive.";
};
get '/:entr', sub {
my $entry = params->{entr};
my $field = exec_sql($entry);
template 'entries' => {
title => $field->{title},
text => $field->{text},
};
};
true;
---------------------------------------------------------------------------------------------------------------------------------------
The everything works correctly when you go to the root directory, everything
is output as expected. But
as soon as you go to http://localhost:3000/hola, the output is a run time
error with a 404 Error.
Please let me know if you need anymore information.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.backup-manager.org/pipermail/dancer-users/attachments/20110114/f77efbcf/attachment.htm>
More information about the Dancer-users
mailing list