I'm making a small web application in python.
Transferring control from one python page to another can be done by form submit or onclick button.This happens at an event.
But I'm searching for a functionality in python similar to 'server.transfer' in asp which is not event dependent.
Please Help.

Dani AI

Generated

Quick clarification: wants a server-side transfer (like ASP's Server.Transfer) so the browser URL does not change and no client event/redirect is required. rightly asked about the environment — since you said you are on Python 2.5 using plain CGI, here are practical, server-side approaches that work in that setup and the trade-offs for each.

A recommended, simple pattern is a front-controller: move page logic into importable Python modules (functions that return headers/body or write to a passed response object). Put one CGI entry script that reads environment and form data once, maps the request to the right function, and emits the headers + body. This keeps the URL unchanged, avoids extra HTTP round-trips, and is portable across servers. Important: read POST data exactly once (cgi.FieldStorage) and pass parsed data into the handler to avoid losing input.

If you must invoke an existing separate CGI script without a client redirect, an alternative is to replace the running process with another script using exec (so the webserver sees the response from that script while the browser URL stays the same). This works but is fragile: you must exec before consuming stdin, preserve/construct the correct CGI environment, and never exec a filename derived directly from user input.

Longer-term, move off raw CGI to WSGI (mod_wsgi, uWSGI, or a microframework like Flask) — WSGI gives clean internal dispatch, better performance, and safer ways to call other handlers internally.

Troubleshooting notes: avoid printing headers twice, sanitize any mapping from request path to code, test both GET and POST flows, and if you run into problems with POST bodies or file uploads, centralize parsing in the front controller so handlers get consistent input.

Recommended Answers

All 3 Replies

You need to give us more information. What framework are you using? Do you simply want to redirect to another page on page load?

You need to give us more information. What framework are you using? Do you simply want to redirect to another page on page load?

I'm using python2.5 script for both client-side and cgi. So you only have python to use.
This problem can be also be solved by a second way if you have a way to use python and javascript together on same page.Is there any way to use python and java script on same page. What server and settings you need to apply this???
Thank You.

Show some of your code. I don't know where you are starting from.

You can send javascript in your response, just as you would send HTML, if you want to use javascript. Of course you can use both. Python runs on the server side and javascipt runs on the client side.

You could also send a 302 status code and specify where in the location header.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.