I would consider fixing this in the stylesheet:

    .popup:empty{ display:none }

or checking for `if request.path == url(...)` in the template