demexp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Demexp-dev] Questions


From: Lyu Abe
Subject: Re: [Demexp-dev] Questions
Date: Sat, 20 Oct 2007 13:59:48 +0900
User-agent: Thunderbird 2.0.0.6 (Windows/20070728)

Hi,

import cgi
form = cgi.FieldStorage()
if form.has_key["login"] ...

But it didn't seem to work. Any suggestions?

It can't work because those two mode are incompatible. Either you are
running a CGI script (i.e. a Python script that is launch each time
Apache handles an URL pointing to this script), or either you use
mod_python and your code runs on a Python interpreter /within/ Apache.

In both cases you should able to get form variables and HTTP headers
info. But you need to look at the correct doc. Haven't doing that
myself, I can't help you further.

If I use the mod python "publisher" handler, then I can pass arguments from the HTML page.

HTML code:
<form method="POST" action="python/login.py/login">
<TABLE border="1" align="center">
<TR><TD>
<TABLE border="0" align="center">
<TR>
<TD align="right">Identifiant:</TD>
<TD><input type="text" name="login" size="20"></TD>
</TR>
<TR>
<TD align="right">Mot de passe:</TD>
<TD><input type="password" name="password" size="20"></TD>
</TR>
<TR>
<TD></TD>
<TD align="right"><input type="submit" value="Envoi"></TD>
</TR>
</TABLE>
</TD></TR>
</TABLE>
</form>

Notice that the "login" function in the python code is called by specifying "login.py/login". I found that it translates into a new (virtual) directory in the folder tree, so that in the python code, if I want to refer to "../css/main.css", I need to write "../../css/main.css"

My folder tree is like this:
>demexp
        >css
                -main.css
        >python
                -login.py
        -index.html



The corresponding Python code is:

from mod_python import apache
import os

def login(req,login,password):
        from xmlrpclib import *
        import sys
                
        req.content_type = "text/html;charset=utf-8"
        req.content_style = "text/css"
        req.write("<html>")
        req.write("<head>")
        req.write('<link href="../../css/main.css" \
                rel="stylesheet" type="text/css"/>')
        req.write("<title>Demexp, the Democratic Experience</title>")
        req.write("</head>")
        req.send_http_header()

        req.write('<body class="body">')
        
        url = "http://www.linux-france.org/cgi-bin/demexp-xmlrpc-demo";

        req.write('Loging in with username %s : %s<br>'\
                %(login,password))
        s = ServerProxy(url)
        cookie = s.login(login, password)
        ...


Best regards, Lyu.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]