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.


In reply to using HTML img tag in Dancer2 by dp235

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.