Mojolicious::Lite - 插入图片问题

发布于 2024-12-01 01:01:20 字数 555 浏览 1 评论 0原文

当我运行此脚本并打开 http://my_server/picture 时,我得到的是 logo 字符串中的图片。

#!/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>

当我将这个 HTML 片段作为普通 HTML 文件打开时,我得到了图片。

使用 Mojolicious::Lite 插入图片的正确方法是什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雪化雨蝶 2024-12-08 01:01:21

public 目录用于存放静态数据。只需在脚本旁边创建它并将图像放入即可。当使用默认设置的开发服务器运行时,您可以通过 url: 访问它,

http://localhost:3000/TEST.jpg

因此您的模板可以包含:

<img src="/TEST.jpg" />

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" />
我最亲爱的 2024-12-08 01:01:21

或者您可以使用: Base64 编码数据文件

...
__DATA__
@@ picture.html.ep
<!DOCTYPE HTML>
<html>
<body>
<p>Hello</p>
<img src="/absolute/path/TEST.jpg" alt="logo" />
<p>World</p>
</body>
</html>

@@ TEST.jpg (base64)
/9j/4AAQSkZJRgABAQEAZABkAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB
AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEB
AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAD6APoDASIA
...

Or you can use: Base64 encoded DATA files:

...
__DATA__
@@ picture.html.ep
<!DOCTYPE HTML>
<html>
<body>
<p>Hello</p>
<img src="/absolute/path/TEST.jpg" alt="logo" />
<p>World</p>
</body>
</html>

@@ TEST.jpg (base64)
/9j/4AAQSkZJRgABAQEAZABkAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB
AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEB
AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAD6APoDASIA
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文