我在我的第一个网站使用耶索德和我的新闻项目的列表:
NewsItem
date UTCTime default=CURRENT_TIME
title String
content String
author String
这是在我的处理程序检索:
newsitems <- runDB $ selectList [] [Desc NewsItemDate]
并最终用在我的模板:
$if null newsitems
<p>No news.
$else
$forall Entity id entry <- newsitems
<article>
<h4>#{newsItemDate entry}
<p>#{newsItemContent entry}
但我得到的数据类型的错误:
Handler/Home.hs:20:11:
No instance for (Text.Blaze.ToMarkup
time-1.4:Data.Time.Clock.UTC.UTCTime)
arising from a use of `toHtml'
Possible fix:
add an instance declaration for
(Text.Blaze.ToMarkup time-1.4:Data.Time.Clock.UTC.UTCTime)
In the first argument of `toWidget', namely
`toHtml (newsItemDate entry_a6ev)'
In a stmt of a 'do' block:
toWidget (toHtml (newsItemDate entry_a6ev))
In the expression:
do { toWidget
((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
"<article><h4>");
toWidget (toHtml (newsItemDate entry_a6ev));
toWidget
((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
"</h4>\
\<p>");
toWidget (toHtml (newsItemContent entry_a6ev));
.... }
所以我想我会继续前进,添加到我的Import.hs:
import Data.Time (UTCTime)
import Data.Time.Format (formatTime)
import Text.Blaze (ToMarkup, toMarkup)
import Text.Blaze.Internal (string)
import System.Locale (defaultTimeLocale)
-- format date as 26 July 2012
instance ToMarkup UTCTime where
toMarkup a = string (formatTime defaultTimeLocale "%e %B %Y" a)
这确实编译,但让我在浏览器中运行时的错误:
Internal Server Error
PersistMarshalError "Expected UTCTime, received PersistText \"2012-08-30\""
所以我不知道如何解决这个问题,任何想法?
编辑:源代码的网站的情况下,它是需要或好奇: https://github.com/iaefai/socrsite