2017-05-08 74 views
-1

這是我的代碼響應:的Python瓶錯誤ValueError異常:View功能沒有返回

@app.route('/registercheck', methods=['GET', 'POST']) 
def registercheck(): 
    checkusername = g.db.execute('select uname from users where uname = ?', (request.form['usernameR'],)) 
    checkpassword = g.db.execute('select pword from users where uname = ?', (request.form['usernameR'],)) 
    arraycheckr = checkpassword.fetchall() 
    if request.method == 'POST': 
     encryptpword = hashlib.md5() 
     encryptpword.update(request.form['passwordR']) 
     encryptpword.digest() 
     if len(arraycheckr) == 0 and checkpassword == encryptpword: 
      if len(request.form['usernameR']) < 6: 
       flash('Username must be at least 6 characters') 
       return redirect(url_for('register')) 
      if len(request.form['passwordR']) < 4: 
       flash('Password must be at least 4 characters') 
       return redirect(url_for(register)) 
      if checkusername == request.form['usernameR']: 
       flash('Username is already taken') 
       return redirect(url_for(register)) 
      else: 
       g.db.execute('insert into users (uname, pword) values (?, ?);', (request.form['usernameR'], encryptpword)) 
       g.db.commit() 
       os.mkdir(os.path.join(app.config['UPLOAD_FOLDER'], request.form['usernameR'])) 
       return redirect(url_for('upload')) 

我看了一下類似這樣的其他職位,但我還是不明白爲什麼它拋出這個問題。重定向看起來很好(在html中)。

+0

那麼,如果方法不是POST,你的代碼會返回什麼?或者,如果它發佈並且密碼無效? –

+0

當請求不是「POST」請求等時會發生什麼? –

回答

0

您接受一個GET請求,你永遠不會檢查,最後你應該渲染一個模板。

@app.route('/registercheck', methods=['GET', 'POST']) 
def registercheck(): 
    checkusername = g.db.execute('select uname from users where uname = ?', (request.form['usernameR'],)) 
    checkpassword = g.db.execute('select pword from users where uname = ?', (request.form['usernameR'],)) 
    arraycheckr = checkpassword.fetchall() 
    if request.method == 'POST': 
     encryptpword = hashlib.md5() 
     encryptpword.update(request.form['passwordR']) 
     encryptpword.digest() 
     if len(arraycheckr) == 0 and checkpassword == encryptpword: 
      if len(request.form['usernameR']) < 6: 
       flash('Username must be at least 6 characters') 
       return redirect(url_for('register')) 
      if len(request.form['passwordR']) < 4: 
       flash('Password must be at least 4 characters') 
       return redirect(url_for(register)) 
      if checkusername == request.form['usernameR']: 
       flash('Username is already taken') 
       return redirect(url_for(register)) 
      else: 
       g.db.execute('insert into users (uname, pword) values (?, ?);', (request.form['usernameR'], encryptpword)) 
       g.db.commit() 
       os.mkdir(os.path.join(app.config['UPLOAD_FOLDER'], request.form['usernameR'])) 
       return redirect(url_for('upload')) 
    return render_template('some_file.html') 
+0

仍然不起作用,它表示:方法不允許 該方法不允許用於請求的URL。 –

+0

你能顯示更新的代碼嗎? – VKolev