def get_param_replace(request, field=None, value=None):
    """
    Cleans up the GET object through URL encoding, and replaces a value in it.

    Usage: {% get_param_replace(request, 'page', '3')  %}

    will output:
    page=3&rest=of&the=GET&string=here
    """
    dict_ = request.GET.copy()

    if field:
        dict_[field] = value

    return dict_.urlencode()