Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python and HTML '% Operator'

Tags:

python

html

css

I'm trying to get some HTML to work with my python code. I've got this for one of my CSS codes.

#footerBar {
height: 40px;
background: red;
position: fixed;
bottom: 0;
width: 100%;
z-index: -1;
}

However, when I try to access the page, I get the following error.

File "projv2.py", line 151, in welcome
</form>""" %(retrievedFullName, retrievedUserName,)
ValueError: unsupported format character ';' (0x3b) at index 1118

I think it's messing with the % since I do use that elsewhere in the HTML.

Any help would be greatly appreciated.

like image 663
user432584920684 Avatar asked Mar 26 '12 12:03

user432584920684


1 Answers

If you want to use % formatting operator, you need to escape your % characters.

So your css should read:

#footerBar {
height: 40px;
background: red;
position: fixed;
bottom: 0;
width: 100%%;
z-index: -1;
}

instead.

It's preferrable to use the string's .format() method instead as it is the preferable way. See PEP 3101 for rationale.

So instead of

...""" % (retrievedFullName, retrievedUserName,)

do

...""".format(retrievedFullName, retrievedUserName)

and change the %s's in your string to {0} and {1}. Of course you need to escape your {}'s in this case, too.

like image 171
Kimvais Avatar answered Sep 29 '22 17:09

Kimvais