2010-06-09 43 views
1

如何從響應中傳遞查詢字符串,同時還應該加載相對模板。Django |如何從響應中傳遞查詢字符串

例如:

http://www.domain.com/test/?id=23423424 

id=23423424是保存在一個數據庫中的關鍵,所以需要處理響應時附上這個。

謝謝。

+0

這不是在都清楚你想要什麼做的。請詳細解釋。 – 2010-06-09 18:04:10

回答

2

據我瞭解,有兩種方法可以做到這一點。您可以在urls.py(和views.py,但稍後)或views.py中執行此操作。

在views.py:

def your_view(request): 
    id = request.GET.get('id', None) 
    ## The rest of your view. 

在urls.py:

urlpatterns = patterns('', 
    (r'^test/\?id=(?P<id>\d+)$', 'path.to.your_view', {}, "your_view_name"), 
) 

信息查看urls.py方法:

def your_view(request, id): 
    ## The rest of your view. 
2

使用request.GET.get('id')從查詢字符串中獲取ID。

相關問題