Django paginate for django 2

2024/10/14 1:12:40

I need to use pagination to a Django list but I couldn't find any help online,, only old docs from Django version 1.3

here are my files :

views.py

def home(request):all_dress = Item.objects.all().filter(dress_active=True)all_good_dress = Item.objects.all().filter(dress_special=True)current_user = request.usercontext = {'all_dress': all_dress,'current_user': current_user,'all_good_dress':all_good_dress,}return render(request, 'fostania/home.html', context)

Template(html)

 {% for item in all_dress %}<div class="card border-info" style="width: 18rem;"><a href="{% url 'dress_details' item.pk%}"><img class="card-img-top" src="{{ item.dress_image1.url }}" alt="Card image cap"></a><div class="card-body" align="right"><h5 class="card-title"><a href="{% url 'dress_details' item.pk%}">{{ item.dress_name }}</a><br>{{ item.dress_action }}<br>{{ item.dress_price }} جنيه </h5><p class="card-text">المقاس : {{ item.dress_size }}<br>{{ item.dress_city }}<br> {{ item.created_at|date:"SHORT_DATE_FORMAT" }}</p></div>
</div><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{% endfor %}
Answer

Found the full doc and clear way to do it on this link https://docs.djangoproject.com/en/2.0/topics/pagination/

https://en.xdnf.cn/q/118015.html

Related Q&A

AttributeError Button object has no attribute scrlFBtn

from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.uix.label import Label from kivy.core.window import Window from kivy.uix.scrollview import ScrollView from kivy.effects.scrol…

How to set interpreter of WinPython as the vim default python interpreter?

I use a Python distribution named WinPython. Now I want my vim to use the python interpreter in WinPython as its default interpreter. I tried add the F:\WinPython\python-2.7.3.amd64 into my windows env…

how to deal with Python BaseHTTPServer killed,but the port is still be occupied?

I use python BaseHTTPServer,it can handle do_GET,do_POST methods,in do_POST method,i execute linux shell using os.system,when i kill the python script,but the listening port still occupied,so i cant ru…

Circular imports and class fields in python3

Okay, I do understand that this topic is old as hell, but I couldnt find an answer to the particular question that I am asking.Lets say that we have a very simple structure: two files, a.py and b.py, t…

Bad HTTP response returned from the server. Code 500

I have a problem to use pywinrm on linux, to get a PowerShell Session. I read several posts and questions on sites about that. But any that can solve my question. The error is in the Kerberos autenti…

Iterate one list of synsets over another

I have two sets of wordnet synsets (contained in two separate list objects, s1 and s2), from which I want to find the maximum path similarity score for each synset in s1 onto s2 with the length of outp…

Flask werkzeug.routing.BuildError

I doing a flask app and when i try to put a link to redirect a user to his profile page by callingBuildError: Could not build url for endpoint profile. Did you forgetto specify values [business_name]?…

getting attribute of an element with its corresponding Id

suppose that i have this xml file :<article-set xmlns:ns0="http://casfwcewf.xsd" format-version="5"> <article><article id="11234"><source><hostn…

How to install selenium python on Mac

Ive downloaded the Selenium zip file for python and it contains the folder with the setup.py. It says on python.org that I have to type in terminal python setup.py install but it gives me this error th…

aws s3 - object has no attribute server_side_encryption

Can someone please explain the differences in these two calls. The first one gives the correct server_side_encryption and the second one gives an error. The other attributes give the same value-#!/usr/…