2014-11-24 69 views
0

我限制您訪問我的客戶門戶以強制客戶訪問主站點以增加每日流量的方式。然而,我試圖找出如何重新編寫Django中的網址,但我不太清楚如何。如何在django中重寫網址

該文檔是有點這個問題上的consufing。我想要重寫的網址是http://127.0.0.1:8000/?enki=0011

我需要取下那個?enki = 0011的部分,因爲這實質上就是檢查。如果用戶在訪問登錄頁面時在URL中有該用戶,則允許他們登錄。但是,如果他們不這樣做,它會將它們重定向到主站點。

+0

@davidism它來自一個joomal網站這就是問題的主要網站沒有在django編程。 – 2014-11-24 20:55:55

回答

1

返回重定向將從URL中「刪除」查詢字符串。店面視圖檢查查詢字符串是否在url中,在會話中設置一個標誌,然後重定向。如果該字符串不存在,並且未設置會話標誌,則會重定向到其他網站。

def storefront(request): 
    if request.GET.get('enki') == '0011': 
     request.session['from_main_site'] = True 
     return redirect('storefront') 
    elif not request.session.get('from_main_site'): 
     return redirect('http://main-site.com/') 

    # at this point the user has come from the main site 
    # and doesn't have "enki" in the url 

    return render(request, 'storefront.html')