2012-11-28 126 views
5

我有一個樣本Web應用程序(燒瓶登錄在heroku上運行)在這個URL:http://twittaclone.herokuapp.com燒瓶登錄和Heroku問題

當我在本地主機上運行它時,登錄功能正常工作。當我推送到heroku它嚇壞了,不允許用戶登錄(它允許用戶註冊)。正在進行數據庫修改。

爲什麼燒瓶登錄不能在heroku上工作?

app = Flask(__name__) 
mysql = MySQL() 

app.config['MYSQL_DATABASE_HOST'] = os.environ['MYSQL_DATABASE_HOST'] if 'MYSQL_DATABASE_HOST' in os.environ else config.MYSQL_DATABASE_HOST 
app.config['MYSQL_DATABASE_PORT'] = os.environ['MYSQL_DATABASE_PORT'] if 'MYSQL_DATABASE_PORT' in os.environ else config.MYSQL_DATABASE_PORT 
app.config['MYSQL_DATABASE_USER'] = os.environ['MYSQL_DATABASE_USER'] if 'MYSQL_DATABASE_USER' in os.environ else config.MYSQL_DATABASE_USER 
app.config['MYSQL_DATABASE_PASSWORD'] = os.environ['MYSQL_DATABASE_PASSWORD'] if 'MYSQL_DATABASE_PASSWORD' in os.environ else config.MYSQL_DATABASE_PASSWORD 
app.config['MYSQL_DATABASE_DB'] = os.environ['MYSQL_DATABASE_DB'] if 'MYSQL_DATABASE_DB' in os.environ else config.MYSQL_DATABASE_DB 

mysql.init_app(app) 

if 'SECRET_KEY' in os.environ: app.config['SECRET_KEY'] = os.environ['SECRET_KEY'] 
else: app.config['SECRET_KEY'] = os.urandom(24) 

def connect_db(): return mysql.connect() 


### 
# Routing for your application. 
### 

login_manager = LoginManager() 
login_manager.login_view = "login" 

@login_manager.user_loader 
def load_user(username): 
    g.db = connect_db() 
    return get_user(username) 

login_manager.init_app(app) 

@app.route('/') 
def home(): return render_template('home.html') 

def connect_db(): return mysql.connect() 

@app.before_request 
def before_request(): 
    g.user = current_user 
    g.db = connect_db() 

@app.teardown_request 
def tear_down(exception): 
    g.db.close() 

@app.route('/main/') 
@login_required 
def main(): 
    print("in main") 
    tweets, user = get_main() 
    follower_count, followee_count = get_follower_info(g.user.username) 
    return render_template('main.html', user=user, tweets=tweets, followercount =  follower_count, followeecount = followee_count) 


@app.route('/login/', methods=['GET', 'POST']) 
def login(): 
    """Logs the user in.""" 
    if request.method == 'GET': 
     if current_user is user_logged_in: logout_user() 

    error = None 
    if request.method == 'POST': 
     user = get_user(request.form['username']) 
     if user is None: 
      error = 'Invalid username' 
     elif not check_password_hash(user.password, request.form['password']): 
      error = 'Invalid password' 
     else: 
      flash('You were logged in') 
      login_user(user) 
      return redirect(url_for('main')) 

    return render_template('login.html', error=error) 
+0

你是什麼意思'怪胎'? – alexvassel

+0

它不斷重定向您登錄多次。 –

+0

嘗試使用名稱a,email:a @ a,password:a等虛擬名稱進行註冊。它會重定向你登錄多次 –

回答