I am writing a basic html program to give input as email and password. Below is the html program
<html>
<body>
<form action='show_commands_html.py' method='get'>
<label for="myname">Enter Your Name</label>
<input id="myname" type="email" name="firstname" value="test@in.com" />
<label for="mypass">Enter Your password</label>
<input id="mypass" type="password" name="Password" value="test121$" />
<input type="submit">
</form>
</body>
</html>
respective python code
import os
print "Content-type: text/html\n"
qs = os.environ['QUERY_STRING']
if 'firstname' in qs:
name = qs.split('&')[0]
name = name.split('=')[1]
if 'Password' in qs:
passw = qs.split('=')[2]
username = name
password = passw
print "<html>"
print "<body>"
print "<h1>%s</h1>" %username
print "</pre>"
print "</body>"
print "</html>"
print "<html>"
print "<body>"
print "<h1>%s</h1>" %password
print "</pre>"
print "</body>"
print "</html>"
I am getting below answers from web page
test%40in.com
test121%24
Instead of
test@in.com
test121$
Any help please ?
Remember to add UTF-8 inside <head>
.
Method 1. You can add new line inside your .py code,
"Content-Type: text/html; charset=UTF-8\r\n";
Method 2. Add new string and test if it works.
u = 'idzie wąż wąską dróżką'
uu = u.decode('utf8')
s = uu.encode('cp1250')
print(s)
Method 3. Add these 2 lines above your code.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
Tip
Make sure, you changed in your code editor:
Settings -> File Encoding -> Switch to: Unicode (UTF-8)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.