[hunchentoot-devel] easy-handler outputs to REPL instead of client
Tyler Smith
tyler.smith at mail.mcgill.ca
Fri Dec 23 16:46:25 UTC 2011
Thank you!
I didn't realize that with-html-output was returning a string, I
thought it was emitting the html to the output as a side effect. In
retrospect, that's silly.
The following works, although it looks a little unwieldy. Any
suggestions for improvement are welcome. Otherwise, thanks for your
help and for all your code.
Cheers,
Tyler
(define-easy-handler (tyler :uri "/tyler") ()
(multiple-value-bind (records fields)
(select [genus] [species] :from "specimens")
(loop for rec in records
collect
(loop
for label in fields
for val in rec
collect (with-html-output-to-string (*standard-output*)
(:dt :class label (str label))
(:dd :class label (str val)))
into inner-output
finally (return (format nil "~{~a~&~}" inner-output)))
into outer-output
finally (return (format nil "~{~a~&~}" outer-output)))))
On Fri, Dec 23, 2011 at 3:05 AM, Edi Weitz <edi at agharta.de> wrote:
> Your loop doesn't return anything, does it?
>
> On Thu, Dec 22, 2011 at 11:51 PM, Tyler Smith
> <tyler.smith at mail.mcgill.ca> wrote:
>> Hi,
>>
>> I'm trying to set up a simple sql-based website using cl-who, cl-sql
>> and hunchentoot. I've got the basic cl-sql and cl-who parts working,
>> but I'm having a trouble serving the pages with hunchentoot.
>>
>> The following works as expected:
>>
>> (ql:quickload :hunchentoot)
>> (use-package :hunchentoot)
>>
>> (setf my-acceptor (start (make-instance 'hunchentoot:easy-acceptor :port 4242)))
>>
>> (define-easy-handler (tyler :uri "/tyler") ()
>> (with-html-output (*standard-output*)
>> (:ul (:li "hi there again"))))
>>
>>
>> After this, if I open localhost:4242/tyler in a browser I see my
>> unordered list. However, with this:
>>
>> (define-easy-handler (tyler :uri "/tyler") ()
>> (multiple-value-bind (records fields)
>> (select [genus] [species] :from "specimens")
>> (loop for rec in records do
>> (loop for label in fields
>> for val in rec do
>> (with-html-output (*standard-output*)
>> (:dt :class label (str label))
>> (:dd :class label (str val)))))))
>>
>> When I browse to localhost:4242/tyler nothing appears in the browser,
>> instead the html is printed in the REPL. If I evaluate just the (M-V-B
>> ...) form without the enclosing (D-E-H ...) it outputs the html to the
>> REPL as I expect.
>>
>> I have been following the examples in the hunchentoot docs, but I'm
>> stumped as to why this doesn't work. What have I missed?
>>
>> Thanks,
>>
>> Tyler
>>
>> _______________________________________________
>> tbnl-devel site list
>> tbnl-devel at common-lisp.net
>> http://common-lisp.net/mailman/listinfo/tbnl-devel
>>
>
> _______________________________________________
> tbnl-devel site list
> tbnl-devel at common-lisp.net
> http://common-lisp.net/mailman/listinfo/tbnl-devel
More information about the Tbnl-devel
mailing list