Stupid Newbie Question Concerning CGI and Reading Forward Slashes

J

Jatinder Singh

Hi Joey,
I am not sure but still I might mean something and give you some clues.
Just try to change / with double slash(//) or with backslash(\ or \\).
next option is read about os module it can give u some hints about how paths
should be written.
Hope These will help.


Quoting "Joey C. said:
Hi, I want to make a configuration script for something and it needs to
read inputs from an HTML file. A couple of these inputs are textboxes
that the user inputs a path in. For example:
Your Home Directory:
[/home/me/public_html/]

So, I'm using Python to read these inputs and store them in a
configuration file. However, I cannot get the CGI to read the forward
slashes (/). It just leaves a blank area. So, for example:
Input: /usr/bin/sendmail
Reads: sendmail

Input: /home/me/public_html/
Reads: (Nothing.)

params = cgi.FieldStorage()

def writep(key, name):
if params.has_key(key):
fconfig.write(name + ": " + os.path.split(params[key].value)[1] +
";\n")

^ This is the function for handling a key that is read by the cgi. The
"name" is the name that it stores the key under so the configuration
file looks like:
name: key;[Line Break]

However, is there a way to get it to read the forward slashes? If
there isn't do you suggest having the user use a different character
and adding a function in the script to substitute a forward slash for
that character?

I tried looking for this for a long while, but maybe I didn't search
enough. Thanks for all of your help and I'm sorry if this is a
question that has been asked 15 million times.

Joey C.
 
J

Joey C.

Hi, I want to make a configuration script for something and it needs to
read inputs from an HTML file. A couple of these inputs are textboxes
that the user inputs a path in. For example:
Your Home Directory:
[/home/me/public_html/]

So, I'm using Python to read these inputs and store them in a
configuration file. However, I cannot get the CGI to read the forward
slashes (/). It just leaves a blank area. So, for example:
Input: /usr/bin/sendmail
Reads: sendmail

Input: /home/me/public_html/
Reads: (Nothing.)

params = cgi.FieldStorage()

def writep(key, name):
if params.has_key(key):
fconfig.write(name + ": " + os.path.split(params[key].value)[1] +
";\n")

^ This is the function for handling a key that is read by the cgi. The
"name" is the name that it stores the key under so the configuration
file looks like:
name: key;[Line Break]

However, is there a way to get it to read the forward slashes? If
there isn't do you suggest having the user use a different character
and adding a function in the script to substitute a forward slash for
that character?

I tried looking for this for a long while, but maybe I didn't search
enough. Thanks for all of your help and I'm sorry if this is a
question that has been asked 15 million times.

Joey C.
 
S

Steve Holden

Joey said:
Hi, I want to make a configuration script for something and it needs to
read inputs from an HTML file. A couple of these inputs are textboxes
that the user inputs a path in. For example:
Your Home Directory:
[/home/me/public_html/]

So, I'm using Python to read these inputs and store them in a
configuration file. However, I cannot get the CGI to read the forward
slashes (/). It just leaves a blank area. So, for example:
Input: /usr/bin/sendmail
Reads: sendmail

Input: /home/me/public_html/
Reads: (Nothing.)
In which case you must be doing something wrong, as this mechanism is
pretty much tried and tested, with no such oddities recorded.
params = cgi.FieldStorage()

def writep(key, name):
if params.has_key(key):
fconfig.write(name + ": " + os.path.split(params[key].value)[1] +
";\n")
You do, I suppose, realize that os.path.split(...)[1] will specifically
remove the leading components of the path?
^ This is the function for handling a key that is read by the cgi. The
"name" is the name that it stores the key under so the configuration
file looks like:
name: key;[Line Break]
This all seems as expected.

Surely it should be the *key* (i.e. the name of the field in the HTML
file) that you use to store the whole value, i.e.:

def writep(key, name):
if params.has_key(key):
fconfig.write("%s: %s" % (name, params[key].value)
However, is there a way to get it to read the forward slashes? If
there isn't do you suggest having the user use a different character
and adding a function in the script to substitute a forward slash for
that character?

I tried looking for this for a long while, but maybe I didn't search
enough. Thanks for all of your help and I'm sorry if this is a
question that has been asked 15 million times.

Joey C.
It's not a common question, but it's relatively easily answered. You are
splitting everything but the filename off with os.path.split and then
complaining about the result! Once you stop doing that your problem is
solved.

regards
Steve
 
J

Joey C.

Steve said:
It's not a common question, but it's relatively easily answered. You are
splitting everything but the filename off with os.path.split and then
complaining about the result! Once you stop doing that your problem is
solved.

Thus, it's a stupid newbie question. Thanks a lot for your help. It
seems I was just being plain stupid.
 
S

Steve Holden

Joey said:
Thus, it's a stupid newbie question. Thanks a lot for your help. It
seems I was just being plain stupid.
Well that's not stupidity, just "over-programming" ;-)

Glad you are moving forward.

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top