Fix #248: Fix next param logic and move logic to Python.

By deciding whether to redirect the user to the next param URL or the
default URL in Python instead of JavaScript, we can rely on Django’s
is_safe_url logic.
`is_safe_url` explicitly returns False for empty urls as far back as Django 1.4: https://github.com/django/django/blob/1.4.13/django/utils/http.py#L228