Formatting tables with CSS

34 views
Skip to first unread message

jason

unread,
Feb 26, 2011, 1:04:11 AM2/26/11
to PyDbLite
Hello all,

I came up with this code to display records in a two-column table
format:

recs = [ r for r in db if q == r['Country']]
#where q = query string submitted from form

for record in recs:
for f in db.fields:
table <= TR(TD(f)+TD(record[f]))

The code works fine but the next step is to make the table look
pretty. In Karrigell, I came up with this HTMLTags code to incorporate
an external stylesheet:

head = HEAD()

head <= LINK(rel="stylesheet", type="text/css", href="style.css")

head <= TITLE('Customer Records')

The title displays just fine but not the CSS formatting. I have the
stylesheet file in the same directory as my Python project file. I
tried using the example code in the Reference Manual. . .

head = HEAD()
head <= LINK(rel="Stylesheet",href="doc.css")
head <= TITLE('Record collection')+stylesheet

. . .but I keep getting an error message stating "stylesheet not
defined." What gives? Any suggestions?

Jason


Pierre Quentel

unread,
Feb 26, 2011, 1:51:33 AM2/26/11
to PyDbLite
Hi jason,

You've been hit by "the only tricking thing in Karrigell" ;-)

If the stylesheet is in the same folder as the script, href must be
"../style.css" : this relative url is resolved using the script url,
which is something like http://host/path/script.py/function. If you
dont put the leading dots, the relative url is resolved as the
absolute url http://host/path/script.py/style.css, resulting in a
"file not found" error

I was hit myself, since the example in the HTMLTags module
documentation should have a correct relative url...

- Pierre

Pierre Quentel

unread,
Feb 26, 2011, 5:09:57 AM2/26/11
to PyDbLite
> which is something likehttp://host/path/script.py/function. If you
> dont put the leading dots, the relative url is resolved as the
> absolute urlhttp://host/path/script.py/style.css, resulting in a
> "file not found" error
>
> I was hit myself, since the example in the HTMLTags module
> documentation should have a correct relative url...
>
> - Pierre

message = message.replace('tricking','tricky')

jason

unread,
Mar 1, 2011, 11:14:40 PM3/1/11
to PyDbLite
Hi Pierre,

For some reason, I wasn't able to get it to work by following your
relative url example. But it works just fine now that I put the css
file in a separate folder:

head <= LINK(rel="Stylesheet",href="css/style.css")

This is probably a better practice anyhow, as it conforms to the rule
of separating content(markup) from presentation(css).

Jason
> which is something likehttp://host/path/script.py/function. If you
> dont put the leading dots, the relative url is resolved as the
> absolute urlhttp://host/path/script.py/style.css, resulting in a
Reply all
Reply to author
Forward
0 new messages