2014-09-22 94 views
0

我有問題,不知道該如何表達它來尋找答案通GET參數HREF鏈接

當我去:http://127.0.0.1:8000/image/test/?title="test"
,然後要到另一個頁面,它會去:http://127.0.0.1:8000/image/test/?page=2" 我叩頭它應該去?http://127.0.0.1:8000/image/test/?title="test&page=2"
但不知道該怎麼辦呢 如何編輯URL來傳遞參數(標題=「測試)去正確的URL

我還有第二個關於網址的問題

,如果我現在對路徑

http://127.0.0.1:8000/image/test/?title="test

我怎麼能寫的絕對HREF去http://127.0.0.1:8000/image/test/

請幫我謝謝

的test.html:

<form action="" method="get" class="searchtitle"> 
     search title:<input type="text" name="title"> 
     <button type="submit" value="submit" >search</button> 
</form> 
... 
<div class="pagination"> 
<span class="step-links"> 
    {% if contacts.has_previous %} 
     <a href="?page={{ contacts.previous_page_number }}">previous</a> 
    {% endif %} 
    <span class="current"> 
     Page {{ contacts.number }} of {{ contacts.paginator.num_pages }}. 
    </span> 
    {% if contacts.has_next %} 
     <a href="?page={{ contacts.next_page_number }}">next</a> 
    {% endif %} 
    <form action="" method="get"> 
     <td>GO to</td> 
     <td><input name="page" type="text" ></td> 
     td> page </td> 
     <td><input type="submit" value=" go to page "></td> 
     </form> 
</span> 

views.py:

def object_list_1(request, model): 
    if request.GET.get("title", None): 
     search_term = request.GET['title'] 
     cls = get_model('mongo', model) 
     obj_list = cls.objects.filter(title__contains=search_term) 
     results = get_paginator(request, obj_list, 10) 
     template_name = 'filterimgs/%s_list.html' % model.lower() 
     return render_to_response(template_name, {'object_list': obj_list,'contacts': results}, 
          context_instance=RequestContext(request)) 

回答

2

問題是這樣的<a href="?page={{ contacts.previous_page_number }}">;在這裏你忽略了任何查詢字符串(?title="test"部分)。

爲了解決這個問題,你需要先enable the request template context processor,然後更新您的模板,以便它包含完整的URL,就像這樣:

<a href="{{ request.get_full_path }}&page={{ contact.previous_page_number }}"> 
+0

我發現這會有一個問題。如果我點擊下頁因爲它是基於''''請求的。因此,網址將變成''''http://127.0.0.1:8000/image/test/?title=「test&page = 2&page = 3&page = 4''''。 get_full_path'''' – user2492364 2014-09-22 14:56:43