如何在转到python中的其他脚本之前对用户进行身份验证
我是python新手,我正在尝试用python建立一个网站,它有两个网页。 'login.html' 'details.html' 但是用户直接进入详细信息页面而没有登录,我怎么才能停止呢 当我使用django使用login_required时,我能够做到这一点,但是当我使用cgi-bin脚本python时,对于webportal,我如何才能停止这一点 请帮我做这个 以下是示例代码: login.html如何在转到python中的其他脚本之前对用户进行身份验证,python,Python,我是python新手,我正在尝试用python建立一个网站,它有两个网页。 'login.html' 'details.html' 但是用户直接进入详细信息页面而没有登录,我怎么才能停止呢 当我使用django使用login_required时,我能够做到这一点,但是当我使用cgi-bin脚本python时,对于webportal,我如何才能停止这一点 请帮我做这个 以下是示例代码: login.html <form action = "login1.py" method = "POST"
<form action = "login1.py" method = "POST">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required>
<br>
<br>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<br>
<br>
<br>
<button type="submit">Login</button>
用户名
密码
登录
details.html
<form action = "copy1.py" method = "POST">
<label for="phone num">Phone num:</label>
<input type = "text" name = "phone num"> <br />
<br >
<br >
<label for="email">Destination path :</label>
<input type = "text" name = "email" />
<br>
<br >
<br >
<div id=submit>
<input type = "submit" value = "Submit" />
电话号码:
目标路径:
login.py:
print("Content-type: text/html")
print("")
import cgi,cgitb
def func():
form = cgi.FieldStorage()
cgitb.enable()
username=form.getvalue('uname')
password = form.getvalue('psw')
userlist=[x,g,d]
passlist=[m,ldf]
if username in userlist:
if password in passlist:
redirectURL = "http://localhost/test/details.html"
print('<html>')
print(' <head>')
print(' <meta http-equiv="refresh" content="0;url='+str(redirectURL)+'" />')
print(' </head>')
print('</html>')
else:
print('<html>')
print('<div id="topcorner"> ')
print("please enter valid password")
print('</div>')
print('</html>')
else:
print('<html>')
print('<div id="topcorner"> ')
print("please enter valid username")
print('</div>')
print('</html>')
print(“内容类型:text/html”)
打印(“”)
导入cgi,cgitb
def func():
form=cgi.FieldStorage()
cgib.enable()
用户名=form.getvalue('uname')
password=form.getvalue('psw')
用户列表=[x,g,d]
passlist=[m,ldf]
如果用户列表中有用户名:
如果密码在passlist中:
重定向URL=”http://localhost/test/details.html"
打印(“”)
打印(“”)
打印(“”)
打印(“”)
打印(“”)
其他:
打印(“”)
打印(“”)
打印(“请输入有效密码”)
打印(“”)
打印(“”)
其他:
打印(“”)
打印(“”)
打印(“请输入有效用户名”)
打印(“”)
打印(“”)
问题:
没有登录,我也可以打开details.html,用户应该在访问其他网站之前先进行身份验证。
请在这方面帮助我如果您的问题不是身份验证,请尝试在脚本中添加以下行
print('Content-Type: text/html')
print('Location: {}'.format(redirectURL))
print() # HTTP says you have to have a blank line between headers and content
print('<html>')
print(' <head>')
...
print('Content-Type:text/html')
打印('位置:{}'。格式(重定向URL))
print()#HTTP表示在标题和内容之间必须有一个空行
打印(“”)
打印(“”)
...
您需要向我们提供后端,而不是前端,而且您使用的是哪种框架,例如Flask?我没有使用任何框架,我使用的是cgi bin python,因为它是一个非常小的网站。您应该看看这里:实际上我的问题不在于身份验证,没有身份验证也使用的是即将打开details.html页面,如果用户输入详细信息页面的url,如果他没有登录,则应重定向到登录页面。当我在地址栏中输入时,它将打开。我希望用户应该重定向到页面,即使他们输入了,这就像django中需要@login_一样,