dp235 has asked for the wisdom of the Perl Monks concerning the following question:
This is my first time using Dancer2 to make a simple website. I'm having problems with the HTML img tag. I wrote a simple route that displays title, an h1, an h2, and an image (jpg). Everything displays as expected except the image. I just get the alt text. Here is the Dancer2 code:
get '/' => sub { template 'index' => { 'title' => 'StoryGen' }; # return "<!DOCTYPE html> <html> <body> " . "<h1> get action </h1> <h2> the dragon </h2> " . '<img src= url("/images/dragon.jpg") alt="A photo of my dragon."> '; }; any qr{.*} => sub { "<h1> default route </h1> "; };
I have sprinkled the image dragon.jpg in several directories around what appears to be the working directories. I have also used several variants on the path in addition to trying the url function. Here is the output from the log on stdout:
C:\Don\StoryGenerator\TestSrc\StoryGen>plackup -p 3000 bin/app.psgi HTTP::Server::PSGI: Accepting connections at http://0:3000/ [StoryGen:11976] core @2019-11-21 18:28:45> looking for get / in C:/St +rawberry/perl/site/lib/Dancer2/Core/App.pm l. 36 [StoryGen:11976] core @2019-11-21 18:28:45> Entering hook core.app.bef +ore_request in (eval 221) l. 1 [StoryGen:11976] core @2019-11-21 18:28:45> Entering hook core.app.aft +er_request in (eval 221) l. 1 127.0.0.1 - - [21/Nov/2019:18:28:45 -0600] "GET / HTTP/1.1" 200 109 "- +" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTM +L, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763" [StoryGen:11976] core @2019-11-21 18:28:45> looking for get /url("/ima +ges/dragon.jpg") in C:/Strawberry/perl/site/lib/Dancer2/Core/App.pm l +. 36 [StoryGen:11976] core @2019-11-21 18:28:45> Entering hook core.app.bef +ore_request in (eval 221) l. 1 [StoryGen:11976] core @2019-11-21 18:28:45> Entering hook core.app.aft +er_request in (eval 221) l. 1 127.0.0.1 - - [21/Nov/2019:18:28:45 -0600] "GET /url(%22/images/dragon +.jpg%22) HTTP/1.1" 200 25 "http://localhost:3000/" "Mozilla/5.0 (Wind +ows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrom +e/64.0.3282.140 Safari/537.36 Edge/18.17763"
I'm puzzled by the "looking for get /url ..." line. I get a similar line for all the variations of the path to the image that I use. That's why I added the catchall route at the end of my code. It does not execute.
Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using HTML img tag in Dancer2
by tobyink (Canon) on Nov 27, 2019 at 11:21 UTC | |
|
Re: using HTML img tag in Dancer2
by Corion (Patriarch) on Nov 26, 2019 at 21:47 UTC |