【问题标题】:Phoenix.Template.UndefinedError at GET /api/todos Could not render "index.json"Phoenix.Template.UndefinedError at GET /api/todos 无法呈现“index.json”
【发布时间】:2022-07-16 05:51:17
【问题描述】:

问题

localhost:4000/api/todos显示错误

Phoenix.Template.UndefinedError at GET /api/todos 无法呈现“index.json”

代码

todo_view.ex

defmodule TodoApiWeb.TodoView do
  use TodoApiWeb, :view
  alias TodoApiWeb.TodoView

  def render('index.json', %{todos: todos}) do
    render_many(todos, TodoView, "todo.json")
  end

  def render('todo.json', %{todo: todo}) do
    %{
      id: todo.id,
    }
  end
end

【问题讨论】:

    标签: phoenix-framework


    【解决方案1】:

    要解决上述问题,请将单引号转换为双引号。 重新加载 localhost:4000/api/todos 以查看 json 是否正确加载。

    【讨论】:

      猜你喜欢
      • 2018-02-01
      • 1970-01-01
      • 2021-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-06
      • 2018-10-31
      • 1970-01-01
      相关资源
      最近更新 更多