Re: Django Pagination paginate dictionary of objects

2020-07-28 Thread jhabar singh
bro try to send a intended code

On Tue, Jul 28, 2020 at 5:16 PM Harvindar Singh Garcha <
garchaama...@gmail.com> wrote:

> I am new to Django, and trying to paginate a dictionary objects,
> However I am unable to so and not getting what's wrong with my code,
> Its still printing whole data on a single page. Above I have posted my
> View along with template code.
>
>
> class Search(ListView):
>  paginate_by = 5
>
>  def get(self, request):
>  if 'search' in request.GET:
>  search = request.GET['search']
>  url = '
> https://api.stackexchange.com/2.2/search/advanced?&site=stackoverflow'
>  params = dict(item.split("=") for item in search.split(","))
>  req = PreparedRequest()
>  req.prepare_url(url, params)
>  stackoverflow_url = req.url
>  response = requests.get(stackoverflow_url)
>  data = response.json()
>  #Data will be like this
>  # data={{'tag':'python','question':'some
> question'},{'tag':'java','question':'some question'}}
>  # n here is 2
>  paginator = Paginator(list(data), 5)
>  page_number = request.GET.get('search')
>  page_obj = paginator.get_page(page_number)
>  return render(request, 'stackoverflow.html', {
>  'data': data,
>  'page_obj': page_obj
>
>  })
>
>
>
>
>
>
>
>
> {%if data %}
> 
>  
> 
>  {% for key,value in data.items %}
>  
>  
> {{ value.title }}
> {{ value.creation_date }} 
>  Asked By  "{{value.owner_link}}">{{value.display_name }} 
>   >Read More →  
>  {% endfor %}
>  
> 
> 
> 
> 
> {% if value.has_previous %}
> « first
> previous
> {% endif %}
>  Page {{ page_obj.number }} of {{
> page_obj.paginator.num_pages }}.
>  
>  {% if page_obj.has_next %}
>  next
> last »
>  {% endif %}
>  
>  
> {% else %}
>  No Results found :(
> {% endif %}
> {% endblock content %}
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f2aeb012-8bad-4234-9a4f-635fe1a8698ao%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJ1QTg%3Dq-dCPgexPQmSZ5w8seqh71K-sByLei%2BXkQHs5soj6WA%40mail.gmail.com.


Django Pagination paginate dictionary of objects

2020-07-28 Thread Harvindar Singh Garcha
I am new to Django, and trying to paginate a dictionary objects,
However I am unable to so and not getting what's wrong with my code,
Its still printing whole data on a single page. Above I have posted my View 
along with template code. 


class Search(ListView):
 paginate_by = 5

 def get(self, request):
 if 'search' in request.GET:
 search = request.GET['search']
 url = 
'https://api.stackexchange.com/2.2/search/advanced?&site=stackoverflow'
 params = dict(item.split("=") for item in search.split(","))
 req = PreparedRequest()
 req.prepare_url(url, params)
 stackoverflow_url = req.url
 response = requests.get(stackoverflow_url)
 data = response.json()
 #Data will be like this
 # data={{'tag':'python','question':'some 
question'},{'tag':'java','question':'some question'}}
 # n here is 2
 paginator = Paginator(list(data), 5)
 page_number = request.GET.get('search')
 page_obj = paginator.get_page(page_number)
 return render(request, 'stackoverflow.html', {
 'data': data,
 'page_obj': page_obj

 })








{%if data %} 
 
  

 {% for key,value in data.items %}
 
  
{{ value.title }} 
{{ value.creation_date }}  
 Asked By {{value.display_name }}  
 
Read More →  
 {% endfor %}
  
 
 
 
 
{% if value.has_previous %} 
« first
previous 
{% endif %} 
 Page {{ page_obj.number }} of {{ 
page_obj.paginator.num_pages }}.
 
 {% if page_obj.has_next %}
 next 
last »
 {% endif %}
 
  
{% else %}
 No Results found :( 
{% endif %} 
{% endblock content %}





-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f2aeb012-8bad-4234-9a4f-635fe1a8698ao%40googlegroups.com.


Django Pagination paginate dictionary of objects

2020-07-28 Thread Harvindar Singh Garcha
I am new to Django, and trying to paginate a dictionary objects, I am 
calling stackoverflow API where I want the result to get paginated. However 
I am unable to so and not getting what's wrong with my code. Above I have 
posted my View along with template code.

>
>
> class Search(ListView):
>  paginate_by = 5
>
>  def get(self, request):
>  if 'search' in request.GET:
>  search = request.GET['search']
>  url = 
> 'https://api.stackexchange.com/2.2/search/advanced?&site=stackoverflow'
>  params = dict(item.split("=") for item in search.split(","))
>  req = PreparedRequest()
>  req.prepare_url(url, params)
>  stackoverflow_url = req.url
>  response = requests.get(stackoverflow_url)
>  data = response.json()
>  #Data will be like this
>  # data={{'tag':'python','question':'some 
> question'},{'tag':'java','question':'some question'}}
>  # n here is 2
>  paginator = Paginator(list(data), 5)
>  page_number = request.GET.get('search')
>  page_obj = paginator.get_page(page_number)
>  return render(request, 'stackoverflow.html', {
>  'data': data,
>  'page_obj': page_obj
>
>  })
>
>>
>>

My template file


{%if data %}
 
 
 
 
 {% for key,value in data.items %}
 
 
 {{ value.title }}
 {{ value.creation_date }} 
  Asked By
 {{value.display_name }} 
 
 Read More →
 
 
 
 {% endfor %}
 
 
 
 
 
 
 
 {% if value.has_previous %}
 « first
 previous
 {% endif %}
 
 Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
 
 {% if page_obj.has_next %}
 next
 last »
 {% endif %}
 
 
{% else %}
 No Results found :(
{% endif %}
 
{% endblock content %}







*Can someone tell me what's wrong with my code, I am unable to get a 
paginated result, everything is coming all together on single page.*




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/683ad3c2-16d6-4eea-9074-5336251165aeo%40googlegroups.com.