0

I am working on CS50W project 2 -- Commerce -- I have decided to use Pagination in my app and it works in showing Active Listing page by page of 5 per page. problem occurs when i try the pagination for categories, it loads first page of 5 listing and when i try to navigate it page to i get MultiValueDictKeyError

my views.py

def categories(request):
    categoriesForm = Categorie.objects.all()    
    return render(request, "auctions/categories.html",{
        'categoriesForm': categoriesForm,
   })

def category_list(request):
    categoriesForm = Categorie.objects.all()
    category = request.POST['category']
    categoryID = Categorie.objects.get(category = category)
    
    listings = Listing.objects.filter(listingCategory = categoryID)
    paginator = Paginator(listings, 5)

    # for paginator
    page = request.GET.get('page', 1)     
    try:
        listingPage = paginator.page(page)
    except PageNotAnInteger:
        listingPage = paginator.page(1)
    except EmptyPage:
        listingPage = paginator.page(paginator.num_pages)
    #end of paginator
    context = {
        "listings": listings,
        "listingPage": listingPage,
        'categoriesForm': categoriesForm,
    }
    return render(request, "auctions/categories.html", context)

my template categories.html

<form id="categprylist" action="{% url 'categorylist' %}" method="POST">
        {% csrf_token %}
        <select name="category" class="form-control">
            <option disabled="true" selected>-- Select The Category --</option>
            {% for category in categoriesForm %}        
                <option>{{ category }}</option>
            {% endfor %}
        </select>
        <input type="submit" value="Submit">
    </form>

my urls.py

path("categories", views.categories, name="categories"),
path("categorylist", views.category_list, name="categorylist"),

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

0

You must log in to answer this question.

Browse other questions tagged .