0

我有一张通过此链接显示的城市卡:

/<country_name>/<city_name>

我可以从两个不同的链接访问这张卡:

/<country_name>/
/<country_name>/pick-cities

打开卡片后,我想返回之前访问过的 URL(以下两个之一)。我使用了一个影响引用的目标:

target = request.META['HTTP_REFERER']

但问题是当我对卡片进行一些操作时,就会request.META['HTTP_REFERER']变成卡片的 URL!(如history.back()在 JavaScript 中)之前是否有其他方法可以链接回访问过的 URL?

4

1 回答 1

0

You could save the request.META['HTTP_REFERER'] in sessions and use it when needed.

Store it only when you come to card url which is different from current url, so you will not save it when you edit it.

Something like

def city_card(request):
    # do your stuff
    if not request.session.get('REFERRER') and request.session['REFERRER'] != request.path
        request.session['REFERRER'] = request.path

    # use request.session['REFERRER'] when you want to redirect there

NOTE: You may have to use something else than request.path to actual url verification.

于 2013-07-08T13:37:02.947 回答