Is there a way to get a referring URL via a custom HTTP header?

Use Django's middleware component.

https://docs.djangoproject.com/en/3.0/topics/http/middleware/

Something like this should work:

class HTTPReferer:

    def __init__(self, get_response):
        self.get_response = get_response

def __call__old(self, request):
    # old
    referer = request.META.get('HTTP_REFERER', None)
    request.referer = referer
    # other business logic as you like it
    response = self.get_response(request)
    return response

def __call__(self, request):
    # reflecting last edit
    path = request.path
    response = self.get_response(request)
    response['previous_path'] = path
    return response

So you could tie any information you need to every request/response cycle in Django (you could also set custom headers, etc...)

In the example above HTTP_REFERER will be available in request object as referer.

EDIT: I think, you concern is that HTTP_REFERER is not always populated by the client; so you could tie HttpRequest.path to every request made to a custom header. If path is not enough, you could save the request args too. That's all, I think. Then you have a custom header populated by the last path. Further on, if this is not enough, you could use Django's URL resolver.