我是Haskell的新手,你也可以向Yesod推测它.我想用两种方法来学习更多关于Haskell和Web开发的方法.
我有两个问题,由于我缺乏Haskell知识,它们都可能是我犯的愚蠢错误:
(1)我用sqlite创建了一个脚手架网站(我使用的是Yesod 1.2).我尝试在生成的homepage.hamlet文件中只添加一行,它给了我一个错误(顺便说一句,没有这个添加,网站工作正常).我添加的行是:
<a href=@{AuthR LoginR}>Go to the login page
Run Code Online (Sandbox Code Playgroud)
之后我收到此错误消息:
Handler/Home.hs:34:11:
Not in scope: data constructor `LoginR'
In the result of the splice:
$(widgetFile "homepage")
To see what the splice expanded to, use -ddump-splices
In a stmt of a 'do' block: $(widgetFile "homepage")
In the second argument of `($)', namely
`do { aDomId <- newIdent;
setTitle "Welcome To Yesod!";
$(widgetFile "homepage") }'
Run Code Online (Sandbox Code Playgroud)
有没有办法在其他处理程序/模板中公开LoginR?
(2)我最终想要自定义登录页面的外观和感觉,所以我试着按照这里的说明(也认为这可能解决了上述问题,因为我在范围内声明了我自己的Handler):http://hackological.com/ blog/using-twitter-to-authenticate-in-yesod /.基本上我修改了Foundation.hs的authRoute语句,如下所示
authRoute _ = Just LoginPanelR
Run Code Online (Sandbox Code Playgroud)
然后添加路线:
/login LoginPanelR GET
Run Code Online (Sandbox Code Playgroud)
并在Home.hs中添加了处理程序
getLoginPanelR :: Handler RepHtml
getLoginPanelR = defaultLayout $(widgetFile "login")
Run Code Online (Sandbox Code Playgroud)
我还创建了相应的login.hamlet文件,其中包含链接中提供的内容.然后我得到以下错误:
Foundation.hs:100:32:
Couldn't match type `App' with `Auth'
Expected type: Route Auth
Actual type: Route App
In the first argument of `AuthR', namely `LoginPanelR'
In the second argument of `($)', namely `AuthR LoginPanelR'
In the expression: Just $ AuthR LoginPanelR
Run Code Online (Sandbox Code Playgroud)
能不能让我知道我做错了什么?
谢谢!
对于(1),只需导入Yesod.Auth.对于(2):看起来,在你的Hamlet模板中,你正在使用它AuthR LoginPanelR.但是,LoginPanelR 不是 auth子网站的一部分,因此应省略AuthR.