在控制器中渲染静态HTML页面 [英] Render static html page in a controller

查看:121
本文介绍了在控制器中渲染静态HTML页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以读取和呈现位于以下位置的静态html文件 控制器中服务器的另一部分?我不希望通过静态页面功能重定向或提供此页面.

Is there a way to read and render a static html file located at another part on server in the controller ? I am not looking to redirect or serve this page via static pages functionality.

推荐答案

您应使用 Plug.Conn.send_file/5 .与将整个文件读入内存然后使用Phoenix.Controller.html/2:

conn
|> put_resp_header("content-type", "text/html; charset=utf-8")
|> Plug.Conn.send_file(200, "/path/to/html")

请注意,我必须手动添加content-type标头才能获得与Phoenix.Controller.html/2相同的行为.

Note that I had to manually add the content-type header to get the same behavior as Phoenix.Controller.html/2.

这篇关于在控制器中渲染静态HTML页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆