I would like to make use of the
HTML::Template
module but somehow I can't set it up to work properly. Here is a very simple representative code I'm testing on:
use strict;
use warnings;
use CGI;
use HTML::Template;
my $test = new CGI;
my $tmpl = HTML::Template->new(filename => 'TemplateSimple.html');
$tmpl->param(
title => 'Test',
body => '<p>This is a test</p>',
);
my $out = $test->header(
-type => 'text/html',
-charset => 'utf-8'
);
print $out;
print $tmpl->output;
When calling the page I always end up with the browser displaying the server error message:
502 - Web server received an invalid response while acting as a gateway or proxy server.
TemplateSimple.html
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<title><TMPL_VAR NAME=title></title>
<link rel="SHORTCUT" ICON href="favicon.ico" />
</head>
<body>
<TMPL_VAR NAME=body>
</body>
</html>
I have to use CGI, because I want to process user input on the web page, but I would like to define the basic HTML structure in a template where I can insert code segments as necessary.
Edit
I think that it could have something to do with different configs between the local Perl (run from eclipse, which does run fine) and the Perl CGI config. Does anybody know of such a case?
Edit
After setting up a Perl CGI configuration in Eclipse, the script runs as expected from the local host. However, the problem when calling the page from an external source persists. So like DaveCross suggested, the bug lies in the web server configuration rather than the Perl script.
perl -c
)? Is HTML::Template installed? It's 2017, why are so many people still writing CGI programs? :-( – Dave CrossContent-Type: text/html; charset=utf-8 HTML::Template=HASH(0x5a2f74)
. When i useprint $tmpl->output
the console output looks as desired, but the in the browser I still get the error message. – N. Maks->output
call, but you've already spotted that). So the problem is in the way your program is interacting with your web server. And you've told us nothing about how that is configured. Saying "I don't know where the server error log is" isn't very helpful. You can't do serious web development without access to the error log. I'm confident there will be useful clues in there. – Dave Cross