榆树前的图像需要存储在静态图像中的图像:
background : Model -> Html Msg
background model =
img
[ src "assets/static/images/main_bg.jpg)"
]
[]
我尝试使用priv/static/images/main_bg.jpg
,但收到相同的错误:
** (Phoenix.Router.NoRouteError) no route found for GET /assets/static/images/main_bg.jpg (PlatformWeb.Router)
(platform) lib/phoenix/router.ex:324: PlatformWeb.Router.call/2
(platform) lib/platform_web/endpoint.ex:1: PlatformWeb.Endpoint.plug_builder_call/2
(platform) lib/plug/debugger.ex:122: PlatformWeb.Endpoint."call (overridable 3)"/2
(platform) lib/platform_web/endpoint.ex:1: PlatformWeb.Endpoint.call/2
(phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:42: Phoenix.Endpoint.Cowboy2Handler.init/4
答案 0 :(得分:1)
您正在向端点GET
发出/assets/static/images/main_bg.jpg
请求,但没有为其定义路由。
如果要提供images
文件夹(即priv/static/images/main_bg.jpg
)的内容,可以在Phoenix Endpoint(lib/my_app_web/endpoint.ex
)中使用Plug.Static。
如果您想指定将要投放的内容,请确保将images
添加到:only
选项:
defmodule MyApp.Endpoint do
use Phoenix.Endpoint, otp_app: :my_app
# Serve at "/" the static files from "priv/static" directory.
#
# You should set gzip to true if you are running phx.digest
# when deploying your static files in production.
plug Plug.Static,
at: "/",
from: :my_app,
gzip: true,
only: ~w(images asset-manifest.json manifest.json)
最后,别忘了将图像src更改为"images/main_bg.jpg"
。