When I run this script and open http://my_server/picture I get instead the picture the logo-string.
#!/usr/local/bin/perl
use warnings;
use 5.014;
use Mojolicious::Lite;
get '/picture' => sub {
shift->render();
};
app->start;
__DATA__
@@ picture.html.ep
<!DOCTYPE HTML>
<html>
<body>
<p>Hello</p>
<img src="/absolute/path/TEST.jpg" alt="logo" />
<p>World</p>
</body>
</html>
When I open this HTML-piece as normal HTML-file I get the picture.
What is the right way, to insert a picture with Mojolicious::Lite?
The public directory is intended for static data. Just create it next to your script and put the image in. When development server with default settings is running, you can access it on url:
http://localhost:3000/TEST.jpg
So your template can contain:
<img src="/TEST.jpg" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With