[Web development with Python] query is also redirect

I am building a web with a web server and Python. As you build, you may create new pages and merge old pages. If a visitor has bookmarked a page, you must notify the visitor that the address has changed.

So there is a way to redirect from the old page to the new page.

#!/usr/bin/env python
# -*- coding:utf-8 -*-
import cgi

form = cgi.FieldStorage()

all_query = '?'
for key in form:
    all_query = all_query \
                + key \
                + '=' \
                + form[key].value + '&'
all_query = all_query[0:len(all_query) - 1]

print ('content-type: text/html; charset=UTF-8\n')
html_body = """\
<html><body>
<script>	
    window.location = '/any.py{0}';
</script>
</body></html>
""".format(all_query)
print (html_body)

Now you don't have to ask to change your bookmarks.

Recommended Posts

[Web development with Python] query is also redirect
[Python] Redirect with CGIHTTPServer
Explosive speed with Python (Bottle)! Web API development
[Web development with Python] Precautions when saving cookies
Web scraping with python + JupyterLab
Web application development with Flask
Web API with Python + Falcon
Web application with Python + Flask ② ③
Web scraping beginner with python
Streamline web search with python
Web application with Python + Flask ④
[python] Reverse with slices! !! (There is also a commentary on slices!)
[Ipdb] Web development beginners tried to summarize debugging with Python
Web application development memo in python
Getting Started with Python Web Applications
Web scraping with Python First step
I tried web scraping with python.
Monitor Python web apps with Prometheus
Get web screen capture with python
Othello game development made with Python
[Hyperledger Iroha] Query with Python library
Python in is also an operator
Prepare Python development environment with Atom
Application development with Docker + Python + Flask
[Web development with Python] Measures against garbled characters when outputting html
WEB scraping with Python (for personal notes)
[Development environment] Python with Xcode [With screen transition]
Getting Started with Python Web Scraping Practice
Daemonize a Python web app with Supervisor
[Personal note] Web page scraping with python3
Web scraping with Python ② (Actually scraping stock sites)
Download files on the web with Python
Horse Racing Site Web Scraping with Python
[Python] A quick web application with Bottle!
Getting Started with Python Web Scraping Practice
Easy web app with Python + Flask + Heroku
Run a Python web application with Docker
Let's make a web framework with Python! (1)
Practice web scraping with Python and Selenium
Easy web scraping with Python and Ruby
PNG saving is slow with Python imageio.imwrite
Let's make a web framework with Python! (2)
[For beginners] Try web scraping with Python
Notify slack when the switch sales page is updated ~ slack bot development with python ③ ~
Split mol2 file with python (-> 2016.04.17 Also supports sdf file)
AWS-Perform web scraping regularly with Lambda + Python + Cron
Python Web Content made with Lolipop cheap server
Vienna with Python + Flask web app on Jenkins
Introduction to Tornado (1): Python web framework started with Tornado
Python log is not output with docker-compose up
Start a simple Python web server with Docker
[Python] Build a Django development environment with Docker
[python] Quickly fetch web page metadata with lassie
[Python] Web development preparation (building a virtual environment)
Launch a web server with Python and Flask
What are you comparing with Python is and ==?
Let's do web scraping with Python (weather forecast)
Let's do web scraping with Python (stock price)
Continuation of multi-platform development with Electron and Python
Extract data from a web page with Python
Get a quick Python development environment with Poetry