0
我一直有我的燒瓶應用程序的縮進問題。
特別是當我嘗試在返回語句之前聲明變量時。另外,當我嘗試在return語句之前使用session['logged_in] = True
時。燒瓶壓痕的縮進錯誤
試圖尋找任何跡象表明我錯誤地構造了這個,我錯過了什麼?
from app import app
from flask import render_template, url_for, request, url_for, redirect, session
from form import NewUser
@app.route('/')
def home():
return render_template('home.html')
@app.route('/logout')
def logout():
session.pop('logged_in', None)
redirect(url_for('home'))
@app.route('/login', methods=['POST', 'GET'])
def login():
form = NewUser()
if request.method == 'POST':
if request.form['username'] != 'admin' and request.form['password'] != 'password':
error = "uername/password incorrect"
return render_template('login.html', form=form, error=error)
else:
session['logged_in'] = True
return redirect(url_for('secretarea'))
return render_template('login.html', form=form, error=error)
@app.route('/secretarea')
def secretarea():
if session['logged_in'] = True:
return "this area is a secret"
else:
error="please log in"
return render_template('login.html', error=error)
我得到的錯誤是這個
File "runserver.py", line 2, in <module>
from app import app
File "/home/roman/flask/myblog/app/__init__.py", line 9, in <module>
from app import views
File "/home/roman/flask/myblog/app/views.py", line 21
return render_template('login.html', form=form, error=error)
^
IndentationError: unexpected indent
2件事 - 1.確保您不混合製表符和空格。 2.您在'logout'端點忘記了'return'語句 – karthikr