0
我有一個家庭作業分配到期,因爲它幾乎完成。但是,我在重定向到另一個模板時遇到了一些問題,歡迎用戶提供簡短的歡迎和提交後提交的用戶名。有人可以看看並告訴我我做錯了什麼嗎?重定向不能使用Python和Flask構建用戶註冊頁面
from flask import Flask, request, redirect, render_template
import cgi
import os
import jinja2
import re
template_dir = os.path.join(os.path.dirname(__file__), 'templates')
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir), autoescape=True)
app = Flask(__name__)
app.config['DEBUG'] = True
@app.route("/")
def index():
template = jinja_env.get_template('index.html')
return template.render()
@app.route("/validate-signup", methods = ['POST'])
def validate_signup():
username = request.form['username']
password = request.form['password']
verifypword = request.form['verifypword']
email = request.form['email']
user_error = ""
pass_error = ""
verifypass_error = ""
email_error = ""
if not username.isalpha():
user_error = "Please enter User Name"
username = ""
elif not re.match("^[a-zA-Z]{3,7}$", username):
user_error = "Must be between 3 and 25 characters"
username = ""
else:
username = request.form['username']
if not password.isalpha():
pass_error = "Please enter Password"
password = ""
else:
password = request.form['password']
if not verifypword.isalpha():
verifypass_error = "Please enter password"
verifypword = ""
elif verifypword != password:
verifypass_error = "Passwords do not match"
else:
verifypword = request.form['verifypass']
if not re.match("[^@][email protected][^@]+\.[^@]+", email):
email_error = "Email must contain @ and ."
else:
email = request.form['email']
if not pass_error and not user_error and not verifypass_error:
return redirect('/welcome'.format(username))
else:
template = jinja_env.get_template('index.html')
return template.render(user_error = user_error,
pass_error = pass_error,
verifypass_error = verifypass_error,
email_error = email_error,
username = username,
email = email)
@app.route('/welcome', methods = ['POST'])
def welcome():
template = jinja_env.get_template('welcome.html')
return template.render
app.run()
你還沒說你的 「小問題」,實際上是什麼。 –
請說明問題的要點 – TheTechGuy
請描述您的問題,儘可能詳細地提供。 [來自評論](https://stackoverflow.com/review/first-posts/17536445) – LW001