Nikolaj Sjujskij committed a52062d

Improve redirection after toggling CSS

Redirect not to '/', but to referrer or `url_for('index')`

Comments (0)

Files changed (1)

 import time
 from psycopg2.extras import DictCursor
-from flask import Flask, abort, redirect, render_template, session
+from flask import (Flask, abort, redirect, render_template, request, session,
+                   url_for)
 app = Flask(__name__)
 from defaults import *
     stylesheet = session.get('css', 'light')
     session['css'] = other_colour(stylesheet)
     session.permanent = True
-    return redirect('/')
+    redirect_url = request.referrer or url_for('index')
+    return redirect(redirect_url)
 app.secret_key = SECRET_KEY