我有一个Flask
应用程序可以与以下views
开头一起使用:
@app.route('/login', methods=['GET', 'POST'])
def do_admin_login():
if request.form['username'] != None:
session['logged_in'] = True
return redirect(url_for('index'))
然后:
@app.route("/index")
def index():
#Auth Step 1: Authorization
url_args = "&".join(["{}={}".format(key,urllib.quote(val)) for key,val in auth_query_parameters.iteritems()])
auth_url = "{}/?{}".format(SPOTIFY_AUTH_URL, url_args)
return redirect(auth_url)
然后:
@app.route("/callback/q")
def callback():
(long callback here)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
print "Getting user playlists..."
playlist = get_user_playlist(USERNAME, sp)
print "Getting playlists contents..."
for i, p in enumerate(playlist):
get_playlist_content(USERNAME, p, sp)
print "Getting playlist # {} audio features...".format(i)
get_playlist_audio_features(USERNAME, p, sp)
print "Sorting..."
return redirect(url_for('homepage'))
最终应将应用引导至:
@app.route('/')
def homepage():
if not session.get('logged_in'):
return render_template('login.html')
else:
return render_template('homepage.html')
使用python app.py
来运行它就像是一种魅力,但是如果我使用 gunicorn 来运行,如下所示,
gunicorn -c gconfig.py app:app --log-level = debug
在终端上,我看到该应用程序经过login()
,index()
,callback()
,但是在login
页面上停了下来,现在重新加载了空白表格,好像没有{ {1}}。
终端输出:
session['logged_in']
配置日志:
127.0.0.1 - - [06/Sep/2018:03:28:07 -0300] "POST /login HTTP/1.1" 302 219 "http://127.0.0.1:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
[2018-09-06 03:28:07 -0300] [18021] [DEBUG] GET /index
127.0.0.1 - - [06/Sep/2018:03:28:07 -0300] "GET /index HTTP/1.1" 302 703 "http://127.0.0.1:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
[2018-09-06 03:28:07 -0300] [18023] [DEBUG] GET /callback/q
Getting user playlists...
Name: Discover Weekly, Number of songs: 30, Playlist ID: 37i9dQZEVXcRI2aS94C6hY
Name: Time, Number of songs: 10, Playlist ID: 1qxOGf3xD3fDQs03kwKteg
Name: Vocoder, Number of songs: 280, Playlist ID: 7nROSBznyIkVgjSdNaHDxm
Getting playlists contents...
Getting playlist # 0 audio features...
Sorting...
Getting playlist # 1 audio features...
Sorting...
Getting playlist # 2 audio features...
Sorting...
127.0.0.1 - - [06/Sep/2018:03:28:16 -0300] "GET /callback/q?code=AQAataXciF5pUIiazCO-6zg3Vd6FX1RuaUJrrFxVgakcVjZkMtb36mi72KzSQBMF_GXgcgPIkFUGdkthnlX09REc4BXycZkAXc6-krXuXRtBUo4bNzjjGbyk-CDDdVl8e8Jj5O_OKs5IJtZ-Wiha647pv3YZgBhAyunjxQ6jid5lt8wXNf71XFxNLNeKnRX0ZH3fpN-z_UP4QXqIuaHoLnmgX9y3xJYem0udlVmM-Qz7QUWc3XEHwbZstygVQYKCXuyolzlGUhBQiOaI12OT8HnqKzZXbVsXQdKGR_9Lni7E46nM HTTP/1.1" 302 209 "http://127.0.0.1:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
[2018-09-06 03:28:16 -0300] [18011] [DEBUG] GET /
127.0.0.1 - - [06/Sep/2018:03:28:16 -0300] "GET / HTTP/1.1" 200 799 "http://127.0.0.1:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
我不能在这里问什么。有人可以指出我正确的方向吗?