In a Python script running under CGI, can I programatically redirect the
program to another page. Assume that I have a static HTML page that I want
displayed (e.g. index.htm). Other than 'print ...' is there any way to
redirect to this URL (for example, like Response.Redirect() in ASP)?
thanks
11 replies to this topic
#1
Posted 27 November 2011 - 02:22 PM
|
|
|
#2
Posted 27 November 2011 - 02:28 PM
I don't know Python, but I had to deal with HTTP in the past. If you haven't sent any HTML, yet, to the client, then you can redirect the browser with a response header, 'location' .
Like in Perl, (if you're still in the header part, that is; if you haven't sent any HTML yet, nor closed the header) you would say:
Like in Perl, (if you're still in the header part, that is; if you haven't sent any HTML yet, nor closed the header) you would say:
print "Location: redirect_to_page.html\r\n";
#3
Posted 27 November 2011 - 03:49 PM
Python has a ton of modules and frameworks out there, so it's possible to find one that might do something that you want, but I don't know of any. I would recommend django framework, as it's super easy and fun to work with.
Or you could do as RhetoricalRuvim said, and just print the redirect.
Or you could do as RhetoricalRuvim said, and just print the redirect.
A conclusion is where you got tired of thinking.
#define class struct // All is public.
#4
Posted 27 November 2011 - 06:43 PM
thanks for the reply but it does not work, what i want is to direct a user to another web page if her login account is okay eg
IN PHP its done this way
Any help on that
if username and password == okay: direct to success_page.py else: direct to errorpage.py
IN PHP its done this way
header("Location: success.php");
Any help on that
#5
Posted 27 November 2011 - 07:06 PM
mutago said:
if username and password == okay:
What do you mean by that? Don't you mean this?:
if username == okay and password == okay:
Even if Python does have weird syntax, I don't think it's that weird.
* * *
mutago said:
header("Location: success.php");In Perl, you can do it like this:
print "Location: success.php\r\n";
Not very different, don't you think? I'm sure it's something similar in Python.
#6
Posted 27 November 2011 - 07:44 PM
thanks but it still not work that way. success.html is a page not words message, cannot be printed. any further suggestion will be appreciated
thanks
thanks
#7
Posted 27 November 2011 - 07:47 PM
Does it redirect at all? Can you provide more details?
#8
Posted 27 November 2011 - 08:09 PM
it returns an error page if i want direct a web page as you said. I think that we are trying to
print a webpage using this
okay consider php as a case study which also use properties print or echo
but to direct a page in php it becomes
thanks
still counting on you
print a webpage using this
print "Location: success.php\r\n";location cannot be printed because its not word message
okay consider php as a case study which also use properties print or echo
but to direct a page in php it becomes
header("Location: success.php");
i think the problem lies in the fact that a web page cannot be printed as we are trying to dothanks
still counting on you
#10
Posted 28 November 2011 - 03:57 PM
@mutago: Are you print'ing the header before anything else on the page? Also, are you closing the header by printing an extra "\r\n" sequence?
@Flying Dutchman: I thought the print keyword did not append new lines to the end of the string it's outputting; doesn't only puts () do that?
@Flying Dutchman: I thought the print keyword did not append new lines to the end of the string it's outputting; doesn't only puts () do that?
#11
Posted 29 November 2011 - 05:11 AM
In Python 2.x print does append new line, unless you end it with comma.
print "Line 1" print "Line 2", print "Line 3" # output Line 1 Line 2 Line 3
A conclusion is where you got tired of thinking.
#define class struct // All is public.
#12
Posted 29 November 2011 - 12:53 PM
thanks you are correct
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









