LoginSignup
1
0

More than 3 years have passed since last update.

[Pythonでweb開発] queryもredirect

Last updated at Posted at 2020-01-19

webサーバとPythonでwebを構築しています。構築していくうちに、新たなページを作成し、古いページを統合する時があります。
閲覧者がブックマークで登録したページがある場合は、閲覧者にアドレスが変わったことを通知しなくてはなりません。

そこで古いページから新しいページにリダイレクトさせる方法があります。

#!/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)

これで、ブックマークの変更依頼をせずに済みます。

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0