阿帕奇显示代码对重定向网页不

问题描述 投票:0回答:1

我有与由python脚本处理的登录表单的网页。当我进入未在数据库中发现一个名字,它重定向到一个login_or_signup.html页面。当我输入一个名称,在数据库中,是应该重定向到一个“next_page.html”页,但它显示了一些代码。为什么它的工作的一种方式,而不是其他? (我已经改变了它去login_or_signup.html页面两种方式,它是双向的。

Python代码

#! /usr/bin/python

import cgi
import cgitb
import mysql.connector as conn
import passlib
from passlib.hash import argon2

import logging

cgitb.enable(logdir="/var/www/html",
             display=False,
             format='text',
             )

logging.basicConfig(level=logging.INFO)

def basic_top(data):
    print """Content-type:text/html\n\n
                <DOCTYPE html>
                <html lang=en">
                    <head>
                        <meta charset= utf-8/>
                        <title>Basic Version</title>
                    </head>
                    <body>"""
    for d in data:
        print d
        print

def go_back_top(data):

    redirectURL = "%s" % "/login_or_signup.html"

    try:
        print """Content-type:text/html\n\n
                    Location: %s""" % redirectURL
        print """<DOCTYPE html>
                        <html lang="en">
                        <head>
                            <meta charset= utf-8/>"""
        print "        <meta http-equiv='refresh' content='0;url=%s' />" % redirectURL
        print """       <title>Login</title>
                        </head>\n\n
                        <body>"""
        #for d in data:
        #   print d
        #   print

        print '    Redirecting... <a href="%s">Click here if you are not redirected</a>' % redirectURL
    except:
        cgi.print_exception()

        print "An error occured\n\n"
        print"<PRE>"
        cgitb.print_exc()

def go_forwards_top(data):

    redirectURL = "%s" % "/login_or_signup.html"  #/next_page.html"
    try:
        print """Content-type:text/html\n\n
                    Location: %s""" % redirectURL
        print """<DOCTYPE html>
                        <html lang="en">
                        <head>
                            <meta charset= utf-8/>"""
        print "        <meta http-equiv='refresh' content='0;url=%s' />" % redirectURL
        print """       <title>Login</title>
                        </head>\n\n
                        <body>"""
        print '    Redirecting... <a href="%s">Click here if you are not redirected</a>' % redirectURL
    except:
        cgi.print_exception()

        print "An error occured\n\n"
        print"<PRE>"
        cgitb.print_exc()

def htmlTail():
    print "</body>"
    print "</html>"

def getData():
    formdata = cgi.FieldStorage()
    username = formdata.getvalue("username")
    password = formdata.getvalue("password")
    login_type = formdata.getvalue("type")

    if login_type == "signup":
        password_copy = formdata.getvalue("password_copy")
        return username, password, password_copy, login_type
    else:
        return username, password, login_type

def connectDB():
    db = conn.connect(user='basic_user', password='twathead', host='127.0.0.1', db="exampleDB")
    cursor = db.cursor()
    logging.info(cursor)
    return db, cursor

def check_person(cursor, data):

    username = data[0]
    sql_str = "SELECT * FROM people WHERE username = '%s'" % (username)
    cursor.execute(sql_str)
    person = cursor.fetchone()

    if person is None:
        go_back_top(data)

    else:       
        go_forwards_top(data)    

    #logging.info(str(conn))
    #conn.close()

if __name__=="__main__":
        logging.basicConfig(filename='/usr/lib/cgi-bin/example.log', level=logging.INFO)
        logging.info('This message should go to the log file')

        #data = ("John", "Smith")
        data = getData()
        #basic_top(data)
        #print "login type = " 
        #print data[0]
        db, cursor = connectDB()
        check_person(cursor, data)  

HTML代码next_page:

    <DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" type="text/css" href="mystyle.css">
        <title>Post Login</title>
    </head>

    <body style="background-color:powderblue;">
        <h2>This page is currently under construction.<h2>

    </body>
</html>
python html apache cgi url-redirection
1个回答
0
投票

开端子,类型:

服务Apache的htcacheclean重启

© www.soinside.com 2019 - 2024. All rights reserved.