问题描述
所以我正在尝试使用 Rust、火箭和柴油制作一个网络应用程序。代码编译得很好,但有一些未使用的衍生警告。但是在渲染模板时出现以下错误
GET /api/users:
=> Matched: GET /api/users (user_list_rt)
=> Error: Error rendering tera template 'user/index'.
=> Error: Failed to render 'user/index': context isn't a JSON object. The value passed needs to be a key-value object: context,struct,hashmap for example.
=> Error: Template 'user/index' Failed to render.
=> Outcome: Failure
=> Warning: Responding with 500 Internal Server Error catcher.
=> Response succeeded.
#[get("/users")]
pub fn user_list_rt(connection: Conn) -> Template {
use crate::schema::user::dsl::*;
let user_coll = user.filter(name.is_not_null())
.load::<User>(&*connection)
.expect("Error loading users");
Template::render("user/index",&user_coll)
}
用户结构
#[derive(Serialize,Queryable,Deserialize,Debug,Clone)]
pub struct User {
pub id: i64,pub uuid: String,pub name: String,pub username: String,pub email: String,pub password: String,pub salt: String,pub phone: i64,pub wallet: i64,pub game_id: String,pub verification: i8,}
我知道我的 user_coll 是用户结构的向量。但我无法弄清楚为什么 Serialize 导数没有自动执行,我错过了什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)