gpwr gpwr - 11 months ago 98
Perl Question

Unable to load images with Mojolicious web server

It would seem that I'm not able to display images with Mojolicious in the web browser. My source code of my Perl script looks like this:


use Mojolicious::Lite;

get '/' => sub {
my $c = shift;
$c->render(text => "Hello World! This is an image: <img src=\"logo.png\"> ");


When I load:
the 'Hello World' text is displayed but the logo.png is not displayed - logo.png appears as a broken image as the web browser reports it is missing. The logo.png file is inside the same directory I'm running the above script from.

What must I do to get images and other external static files like javascript files, css, etc. to load inside the web page.

Answer Source

By default, Mojolicious serves static from the public subdirectory of your application. Try putting the image file in there. You can change the static file directory using $app->static.