Python php跳转页面,Python CGI:如何在处理POST d之后重定向到另一个页面

我正在尝试用pyscripts/find_match.py编写一个Python脚本,它将处理upload.php页面中从POST接收到的数据,将其发送到connect.php,然后重定向到另一个php页面response.php,该页面将根据我处理的数据显示信息,并且具有<?php include '/connect_database.php';?>

行。

到目前为止,我能够获取POST信息,对其进行处理并通过JSON将其发送到connect.php,但是我无法将find_match.py重定向到response.php。我的代码如下:

在pyscripts/find_match.py中:print "Content-type: text/html"

print

print "

"

print "

"

import cgi

import cgitb

cgitb.enable()

try:

form = cgi.FieldStorage()

fn = form.getvalue('picture_name')

cat_id = form.getvalue('selected')

except KeyError:

print 'error'

else:

# code to process data here

data_to_be_displayed = # data to be used in connect.php; it's an array of ids

import httplib, json, urllib2

headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}

conn = httplib.HTTPConnection('192.168.56.101:80')

#converting list to a json stream

data_to_be_displayed = json.dumps(data_to_be_displayed, ensure_ascii = 'False')

conn.request("POST", "/connect_database.php", data_to_be_displayed, headers)

response = conn.getresponse()

text = response.read()

# print response.status, text

conn.close()

# WHAT I WANT TOT DO HERE

if response.status == 200:

redirect('/response.php')

print ""

在response.php中:

Response Page

我找到了一些关于urllib.HTTPRequestHandler类和Location头的信息,但是我不知道如何使用它们。

尝试使用

在头牌上,但没用。

请帮忙。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python中,可以使用web框架(如Django或Flask)来实现页面之间的跳转。具体实现方法如下: 1. 首先,需要安装所选框架并创建一个新的项目。 2. 在项目中创建两个视图函数,分别对应第一个页面和第二个页面。 3. 在第一个视图函数中,使用重定向函数将请求重定向到第二个页面的URL。 4. 在第二个视图函数中,返回第二个页面的HTML模板或其他响应。 以下是一个使用Django框架实现页面跳转的示例代码: ```python # 导入Django的重定向函数 from django.shortcuts import redirect, render # 第一个页面的视图函数 def first_page(request): # 重定向到第二个页面的URL return redirect('/second_page') # 第二个页面的视图函数 def second_page(request): # 返回第二个页面的HTML模板 return render(request, 'second_page.html') ``` 在上述示例中,当用户访问第一个页面时,视图函数`first_page`会将请求重定向到`/second_page`,然后由`second_page`视图函数返回第二个页面的HTML模板。 请注意,上述示例是使用Django框架实现的,如果使用其他框架,具体实现方式可能会有所不同。 #### 引用[.reference_title] - *1* *2* *3* [python之路_python可变数据类型及页面跳转](https://blog.csdn.net/weixin_39681486/article/details/110145238)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值