嘿,我正试着让我正在制作的网站发送一个曲奇给用户,然后显示一个网页。
因此,我发现tutorial/是关于如何制作cookie的唯一真正的教程,但它似乎对我来说是错误的。
我的循环看起来像这样(我的make_cookie、get_cookie_value、render_ok和get_username与他的相同,除了我用'mename‘作为键而不是’用户名‘):
loop(Req, DocRoot) ->
"/" ++ Path = Req:get(path),
try
case dispatch(Req, valid_urls:urls()) of
none ->
case filelib:is_file(filename:join([DocRoot, Path])) of
true ->
%% If there's a static file, serve it
Req:serve_file(Path, DocRoot);
false ->
%% Otherwise the page is not found
case Req:get(method) of
Method when Method =:= 'GET'; Method =:= 'HEAD' ->
case Path of
"response" ->
QueryStringData = Req:parse_qs(),
Username = get_username(Req, QueryStringData),
Cookie = make_cookie(Username),
FindCookie = get_cookie_value(Req,"mename","Not Found."),
% render_ok(Req, [Cookie], greeting_dtl, [{username, Username}]),
Req:respond({200, [{"Content-Type", "text/html"}],
"<html><p>Webpage</p></hmtl>"});
_ ->
Req:not_found()
end
end
end;
Response ->
Response
end
catch
Type:What ->
Report = ["web request failed",
{path, Path},
{type, Type}, {what, What},
{trace, erlang:get_stacktrace()}],
error_logger:error_report(Report),
%% NOTE: mustache templates need \ because they are not awesome.
Req:respond({500, [{"Content-Type", "text/plain"}],
"request failed, sorry\n"})
end.我得到的错误是:
[error] "web request failed", path: "response", type: error, what: undef, trace: [{greeting_dtl,render,[[{username,"GET"}]],[]}这个错误似乎来自于render_ok,但是对于来说,我并不确定如何解决这个问题。
发布于 2014-11-25 06:04:00
您已经将render_ok注释掉了,但是在此之后没有编译该文件。错误消息表明,它仍然调用greeting_dtl。
我假设您使用的是erlydtl,因为错误在greeting_dtl中。render函数中的错误通常意味着您拼写错了某个属性名。检查模板在哪里,以及它是否有类似于{{ something.username }}的内容。将其注释掉或更改为mename (任何有意义的内容)。
https://stackoverflow.com/questions/27114558
复制相似问题