파이썬에서 html로 값을 전달하고싶습니다.

lgs0071의 이미지

안녕하세요 컴퓨터공학과 학생입니다.
파이썬 프로젝트로 웹으로 설문조사 하기를 간단하게 구현하려고합니다.

①httpd서버를 구동시켜서 로그인 폼에서 회원가입을 한뒤 cgi를 import시킨 파이썬프로그램에서 db에 회원가입정보를
저장합니다.

②다시 로그인 폼으로 돌아와 로그인을 하면 login.py에서 html폼으로부터 전달받은 값과 db와 대조하여 있는 값이면 설문조사 html로 이동합니다.

③그다음 설문조사 결과를 cgi를 import시킨 파이썬프로그램에 보내어 db에 저장하려고 합니다.

여기서 로그인을 한 id값을 db에서 찾아 설문조사 결과를 저장시켜야하는데 ①번에서 파이썬(.py)에서 html로 id값을 전달하는 방법을 모르겠습니다.

하고싶은 방법은 파이썬프로그램에서 html로 값을 전달하여 html에서 그 값을 출력하는것입니다.
혹시 방법을 알고계신분은 알려주시면 감사하겠습니다.

f의 이미지

제가 그 비슷한 작업을 하고 있어 적어봅니다.
하려는 작업에 힌트가 될 수 있을지 모르겠네요.

#!/usr/bin/env python
# -*- coding:utf8 -*-
 
from __future__ import print_function
import cgi
import cgitb    # show cgi script error in browser
 
def print_header(title = ''):
    print ('Content-type: text/html\n') # ":" 다음에 공백 주의
    print ('<!DOCTYPE html>\n<html>')
    if title != '':
        title = '<title>%s</title>\n' % title
    print ('<head>')
    print('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">')
    print('<meta http-equiv="cache-control" content="max-age=0" />')
    print('<meta http-equiv="cache-control" content="no-cache" />')
    print('<meta http-equiv="expires" content="0" />')
    print('<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />')
    print('<meta http-equiv="pragma" content="no-cache" />')
    print('%s</head>' % title)
    pass
 
 
def print_pre(str):
    print('<pre>%s</pre>' % str)
    pass
 
print_header()
 
print ('<body>')
 
import time
print('<p>%s</p>' % time.ctime())
 
p = '''\
<form method=post>
<input type=submit name='open' value='open'></input>
<input type=submit name='close' value='close'></input>
</form>
'''
print(p)
 
import os
print('<pre>')
# <a href="https://stackoverflow.com/questions/1873735/display-the-result-on-the-webpage-as-soon-as-the-data-is-available-at-server
sys.stdout.flush" rel="nofollow">https://stackoverflow.com/questions/1873735/display-the-result-on-the-webpage-as-soon-as-the-data-is-available-at-server
sys.stdout.flush</a>()
 
print('</pre>')
 
valo= ''
valc= ''
 
form = cgi.FieldStorage()
 
if 'open' in form:
    valo = form['open'].value
if 'close' in form:
    valc = form['close'].value
 
print_pre('%s%s' % (valo, valc))
print_pre('%s' % form)
 
# <a href="https://stackoverflow.com/questions/1873735/display-the-result-on-the-webpage-as-soon-as-the-data-is-available-at-server
sys.stdout.flush" rel="nofollow">https://stackoverflow.com/questions/1873735/display-the-result-on-the-webpage-as-soon-as-the-data-is-available-at-server
sys.stdout.flush</a>()