📜  使用 python cgi 代码根据输入重定向用户 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:46.075000             🧑  作者: Mango

代码示例1
# Import modules for CGI handling 

    import cgi, cgitb 

    # import pymongo module for connecting to mongodb database
    import pymongo
    from pymongo import MongoClient

    # Create instance of FieldStorage 
    form = cgi.FieldStorage() 

    # creating a mongo client to the running mongod instance
    # The code will connect on the default host and port i.e 'localhost' and '27017'
    client = MongoClient()

    # selecting the database mydb 
    db_mydb = client.mydb

    # selecting the collection user
    collection_user = db_mydb.user

    #print "Content-type:text/html\r\n\r\n"

    # Get data from fields
    email = form.getvalue('login-username')
    password  =     form.getvalue('login-password')

    #checking whether user inputs are correct or not
    existence_query = collection_user.find_one({"_id":email,"password":password})


    if(existence_query):
        print "Location:http://localhost/mongo/index.html\r\n"
        print "Content-type:text/html\r\n\r\n"
    else:
        print "Location:http://localhost/mongo/index.html\r\n"
        print "Content-type:text/html\r\n\r\n"