首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建然后访问Mochiweb Cookies

创建然后访问Mochiweb Cookies
EN

Stack Overflow用户
提问于 2014-11-24 21:32:33
回答 1查看 156关注 0票数 0

嘿,我正试着让我正在制作的网站发送一个曲奇给用户,然后显示一个网页。

因此,我发现tutorial/是关于如何制作cookie的唯一真正的教程,但它似乎对我来说是错误的。

我的循环看起来像这样(我的make_cookie、get_cookie_value、render_ok和get_username与他的相同,除了我用'mename‘作为键而不是’用户名‘):

代码语言:javascript
复制
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.

我得到的错误是:

代码语言:javascript
复制
[error] "web request failed", path: "response", type: error, what: undef, trace: [{greeting_dtl,render,[[{username,"GET"}]],[]}

这个错误似乎来自于render_ok,但是对于来说,我并不确定如何解决这个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-25 06:04:00

您已经将render_ok注释掉了,但是在此之后没有编译该文件。错误消息表明,它仍然调用greeting_dtl

我假设您使用的是erlydtl,因为错误在greeting_dtl中。render函数中的错误通常意味着您拼写错了某个属性名。检查模板在哪里,以及它是否有类似于{{ something.username }}的内容。将其注释掉或更改为mename (任何有意义的内容)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27114558

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档