NoReverseMatch at / django python:Reverse for '*' not found. tried - django

Reverse for 'details' with arguments '('',)' not found. 1 pattern(s) tried: ['details/(?P[.\-\w]+)$']
I am getting this error when I open the home page. All other pages seem to work.
urls.py
app_name = 'main'
urlpatterns = [
url(r'^$', views.home, name='home'),
url(r'ask-question/$', views.question, name='ask-question'),
url(r'^details/(?P<slug>[.\-\w]+)$', views.details, name='details'),
]
views.py for the home page
def home(request):
questions = Question.objects.all().order_by("-date")
numbers = Question.objects.all().count()
numbers2 = Answer.objects.all().count()
total_users = User.objects.all().count()
# counting answers on specific questions
results = Question.objects.annotate(num_answers=Count('answer')).order_by("-date")
# PAGINATION ===============================
page = request.GET.get('page', 1)
paginator = Paginator(results,10)
try:
results = paginator.page(page)
except PageNotAnInteger:
results = paginator.page(1)
except EmptyPage:
results = paginator.page(paginator.num_pages)
# end of counting
empty = []
for a in Answer.objects.all():
idd = a.id
question_id = (a.question_id)
empty.append(str(question_id))
repeatition = Counter(empty)
# i = 0
# trend_list = []
# for x in range(len(repeatition)):
# new = repeatition.most_common()[i][0]
# trend_list.append(new)
# i += 1
# if len(trend_list) != 0:
# trend = Question.objects.get(id=trend_list[0])
# else:
# trend = 'No Trending Category'
# getting the answers to all questions in the front page
# search the questions ============
query= request.GET.get("q")
if query:
short_list = Question.objects.all()
questions = short_list.filter(title__icontains=query)
resulted = questions.annotate(num_answers=Count('answer'))
counted = questions.count()
context1 = {
'questions': questions,
'query': query,
'counted': counted,
'resulted': resulted,
}
return render(request, 'main/search.html',context1)
context = {
'questions': questions,
'numbers': numbers,
'numbers2': numbers2,
'total_users': total_users,
# 'trend': trend,
'results': results,
}
return render(request, 'main/index.html', context)
index.html
{% extends 'main/base.html' %} {% block content %}
<div class="container">
{% for message in messages %}
<div class="alert alert-{{ message.tags }} alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button> {{ message }}
</div>
{% endfor %}
</div>
<!-- end of the message container -->
<!-- start of the actual questions -->
<div class="container-fluid">
<h1 class="text-left" id="brand"> Recently Added Questions</h1>
<div class="row">
<div class="col-md-8">
<div id="qtns">
{% for q in results %}
<a href="{% url 'main:details' q.slug %}" id="questions">
<h4 id="titleq">{{ q.title }}</h4>
</a>
<a href="{% url 'main:filter' q.category %}">
<p class="badge badge-info">{{ q.category }}</p>
</a>
<p id="titleq">{{ q.date |timesince }} ago. {{ q.user }}</p>
<div class="text-right">
<p>Answers: {{q.num_answers}}</p>
</div>
<hr> {% endfor %}
</div>
</div>
<div class="col-md-3">
<div id="qtns1">
<br> {% if not user.is_authenticated %}
Ask Question<br><br> {% else %}
Ask Quesiton<br><br> {% endif %}
<div class="qtns2">
<h1 id="titleq">Statistics</h1>
<p>Questions asked: {{numbers}} </p>
<p>Answers: {{ numbers2 }}</p>
<p>Total Users: {{ total_users }}</p>
</div> <br>
<div class="qtns2">
Most answered:
<a href="{% url 'main:details' trend.slug %}" style="text-decoration:none;">
<p>{{ trend }}</a> - <i>{{ trend.user }}</i></p>
<p><i>Posted On: </i>{{ trend.date}}</p>
</div>
<br>
<div class="qtns2">
Most Questions By:
<a href="{% url 'accounts:profile' trend.user %}" style="text-decoration:none;">
<p>{{ trend.user }}</p>
</a>
</div>
</div>
</div>
</div>
<br>
<!-- pagination for the limited display of questions -->
<nav aria-label='pagination'>
{% if results.has_other_pages %}
<ul class="pagination">
{% if results.has_previous %}
<li class="page-item"><a class="page-link" href="?page={{ results.previous_page_number }}">«</a></li>
{% else %}
<li class="page-item disabled"><span class="page-link">«</span></li>
{% endif %} {% for i in results.paginator.page_range %} {% if results.number == i %}
<li class=" page-item active"><span class="page-link">{{ i }} <span class="sr-only">(current)</span></span>
</li>
{% else %}
<li class="page-item"><a class="page-link" href="?page={{ i }}">{{ i }}</a></li>
{% endif %} {% endfor %} {% if questions.has_next %}
<li class="page-item"><a class="page-link" href="?page={{ results.next_page_number }}">»</a></li>
{% else %}
<li class=" page-item disabled"><span class="page-link">»</span></li>
{% endif %}
</ul>
</nav>
</div>
{% endif %} {% endblock %}
All other pages are working, but the home page is returning reverse for 'details' ..... not found. What seems to be the problem, I can't figure it out. Can anyone please look at my code and tell me my mistake. Thanks in advance.

Every time you encounter an error you need to have a debugging strategy. In NoReverseMatch case the strategy would be:
Find all the cases where reverse for 'details' is called.
Check that cases validate by asking yourself three questions:
Is object in the context?
Is field (or key/value) you're trying to get part of this object?
Is value as expected?
All answers must be yes. If the answer is no, fix it.
Cases where reverse for 'details' is called are:
<a href="{% url 'main:details' q.slug %}" id="questions">
<a href="{% url 'main:details' trend.slug %}" style="text-decoration:none;">
Are q and trend in the context? q is as part of results object, that is a yes and trend isn't in the context, because you commented that part of the code in your views. trend.slug thus returns nothing and reverse for 'details' with nothing is not found, because slug is expected.
If you fix this, this error should go away.

Related

Adding a tag to a pagination element django

When creating a pagination, everything works as it should. Added (?page= page number selection) pagination.
How can I add the pagination page number to its object?
When selecting an object and reloading the page, I need it to be spelled out in the URL (/?page=pagination number).
And the pagination remained on the selected page.
class MovieShow(DetailView):
model = Movie
template_name = 'movies/movie_play.html'
context_object_name = 'movie'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['object_list'] = Movie.objects.filter(course__slug=self.kwargs['course_slug'])
context['title'] = context['movie']
paginator = Paginator(context['object_list'], 1)
page = self.request.GET.get('page')
try:
context['object_list'] = paginator.page(page)
except PageNotAnInteger:
context['object_list'] = paginator.page(1)
except EmptyPage:
context['object_list'] = paginator.page(paginator.num_pages)
return context
This is how I present pagination in the template
<div class="pagination" id="pagination">
<span class="step-links" >
{% if object_list.has_previous %}
<a class="page-link" href="?page=1"> << </a>
<a class="page-link" href="?page={{ object_list.previous_page_number }}"> < </a>
{% endif %}
<span class="current">
{{ object_list.number }} из {{ object_list.paginator.num_pages }}
</span>
{% if object_list.has_next %}
<a class="page-link" href="?page={{ object_list.next_page_number }}"> > </a>
<a class="page-link" href="?page={{ object_list.paginator.num_pages }}"> >> </a>
{% endif %}
</span>
And so I have a search of the elements inside the pagination, on which I want to hang the pagination page number.
I really hope I asked the question correctly.
I will be glad of any help!
<div class="video_courses" id="block-posts">
{% for c in object_list %}
<a class="a_hover" href="{{ c.get_absolute_url }}">
<div class="video_courses_block">
<div class="video_courses_block_img"><img src="{{ c.poster.url }}" alt=""></div>
<div class="video_courses_block_text">
<div class="video_courses_block_text_title"><h2>[ {{ c.author }} ] {{ c.title }}</h2></div>
<div class="video_courses_block_text_navigation">
<div class="video_courses_block_text_left">{{ c.category }}</div>
<div class="video_courses_block_text_rig">{{ course.movie_set.count }}</div>
</div>
</div>
</div>
</a>
{% endfor %}
{% include 'pagination.html' %}
You just need to add if to the link and specify the page number
{% for c in object_list %}
{% if object_list.number %}
<a class="a_hover" href="{{ c.get_absolute_url }}?page={{ object_list.number }}">
{% endif %}
<div class="video_courses_block">
<div class="video_courses_block_img"><img src="{{ c.poster.url }}" alt=""></div>
<div class="video_courses_block_text">
<div class="video_courses_block_text_title">
<h2>[ {{ c.author }} ] {{ c.title }}</h2>
</div>
<div class="video_courses_block_text_navigation">
<div class="video_courses_block_text_left">{{ c.category }}</div>
<div class="video_courses_block_text_rig">{{ course.movie_set.count }}</div>
</div>
</div>
</div>
</a>
{% endfor %}
</div>
{% include 'pagination.html' %}

HTMX not working when using paginate with infinite-scroll

I have a product card in my Django Application, when clicked, adds to cart. I'm using infinite-scroll and django-pagination.
The issue is with the pagination, however. The first page of results works wonderfully with HTMX. However, the second page and all pages beyond does not work on click. Upon inspecting the page, the html does appear to be rendered properly and I can see the hx-get call with the proper url. But upon clicking, nothing happens.
Maybe I'm missing something obvious here, but any help would be appreciated!
HTML
<div class="container"
data-infinite-scroll='{ "path": ".pagination__next", "append": ".product-card", "history":"false"}'>
{% block content %}
{% include 'includes/cards.html' %}
{% include 'includes/sidebar.html' %}
{% endblock content %}
</div>
<ul class="pagination mt-50 mb-70">
{% if products.has_previous %}
<li class="page-item"><a class="page-link" href="?page={{ products.previous_page_number }}"><i class="fa fa-angle-left"></i></a></li>
{% endif %}
<li class="page-item"><a class="page-link" href="#">{{ products.number }}</a></li>
{% if products.has_next %}
<li class="page-item"><a class="pagination__next" href="?page={{ products.next_page_number }}"><i class="fa fa-angle-right"></i></a></li>
{% endif %}
</ul>
views.py
def shop(request):
anabanner = AnaBanner.objects.all()
gender = Gender.objects.all()
categories = Category.objects.all()
colors = Color.objects.all()
materials = Material.objects.all()
query = request.GET.get('query','')
products = Product.objects.all().order_by('-pk')
if query:
products = products.filter(
Q(name__icontains=query)|
Q(sub_name__icontains=query)
).distinct()
paginator = Paginator(products, 8)
page = request.GET.get('page')
products = paginator.get_page(page)
context = {'products':products,'categories':categories,'gender':gender,'anabanner':anabanner,'colors':colors,'materials':materials}
return render(request, 'shop.html', context)
Button
<div class="button">
<div class="button-layer"></div>
<button name="ekle"
href ="#"
hx-get="{% url 'add_to_cart' product.id %}"
hx-target="#menu-cart-button"
hx-swap="outerHTML"
class="btn btn-outline-secondary add-btn update-cart">Sepete Ekle</button>
</div>
Here i my Infinite scroll pattern django with HTMX
urls.py
highlights_urls = [
path('<slug:slug>/',
views.highlight_detail,
name='highlight_detail',
),
]
urlpatterns = [
path('highlights/', include(highlights_urls)),
]
views.py
def highlight_detail(request, slug: str):
object: Highlight = get_object_or_404(Highlight, slug=slug)
template_name = 'highlight/highlight-detail.html'
if request.htmx:
template_name = 'highlight/partials/highlight-detail-partial-elements.html'
page_number = request.GET.get('page', default=1)
paginator = Paginator(object.products.all(), settings.PAGINATION_PAGE_SIZE)
page_obj = paginator.get_page(page_number)
context = {
'object': object,
'page_obj': page_obj
}
return TemplateResponse(request, template=template_name, context=context)
highlight-detail.html
<section class="padding-top">
<div class="container">
<header class="section-heading">
<h3 class="section-title">{{ object.name }}</h3>
</header>
<div class="row" hx-indicator=".htmx-indicator">
{% include './partials/highlight-detail-partial-elements.html' %}
</div>
</div> <!-- container end.// -->
highlight-detail-partial-elements.html
{% for product in page_obj %}
<div
{% if forloop.last and page_obj.has_next %}
hx-get="{% url 'highlight_detail' object.slug %}?page={{ page_obj.number|add:1 }}"
hx-trigger="revealed"
hx-swap="afterend"
hx-target="this"
{% endif %}
class="col-6 col-sm-4 col-md-3 col-lg-3 col-xl-3">
{% include 'highlight/includes/product-card.html' with object=product %}
</div>
{% endfor %}

Django search pagination error, page not found error each time I try to move to page 2

I'm popping up with an error on my comic book ecommerce application. It's a Django app. Basically, the search function isn't paginating properly, giving me a page not found error each time I try to move to page 2 and onwards. It works fine in my general products listing area though, where there is no q-based search.
It works fine when I paginate just the products section, adding in...
paginate_by = 6
...into the class ListView section...
...and adding this section into the view.html section...
<div class="pagination">
<span class="step-links">
{% if page_obj.has_previous %}
« first
previous
{% endif %}
<span class="current">
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
</span>
{% if page_obj.has_next %}
next
last »
{% endif %}
</span>
</div>
...But, once I try to paginate the search function in the same way, it appears to paginate, but page 2 and onwards just gives me a page not found error...
http://127.0.0.1:8000/search/?page=2
Request Method: GET
Request URL: http://127.0.0.1:8000/search/?page=2
Raised by: search.views.SearchProductView
....I think it has something to do with q, and the view.html section, but I'm not sure.
Any help would be much-appreciated.
Also, here's my view.html:
{% extends "base.html" %}
{% block content %}
<!-- <div class="pagination">
<span class="step-links">
{% if page_obj.has_previous %}
« first
previous
{% endif %}
<span class="current">
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
</span>
{% if page_obj.has_next %}
next
last »
{% endif %}
</span>
</div> -->
<!--the heading with the result of the name-->
<div class="row mb-3">
{% if query %}
<div class="col-12">
Results for <b>{{ query }}</b>
<hr/>
</div>
{% else %}
<div class="col-12 col-md-8 mx-auto py-5">
{% include 'search/snippets/search-form.html' %}
</div>
<div class="col-12">
<hr>
</div>
{% endif %}
</div>
<!--create a card/item for each comic-->
<div class="row">
{% for obj in object_list %}
<div class="col">
{% include 'products/snippets/card.html' with instance=obj %}
{% if forloop.counter|divisibleby:3 %}
</div>
</div>
<!--or else if no item just create a blank row and column-->
<div class='row'><div class='col-12'><hr/></div>
{% else %}
</div>
{% endif %}
{% endfor %}
{% endblock %}
And here's a snippet that works within the view.html (search-form.html)
<form method="GET" action='{% url "search:query" %}' class="form my-2 my-lg-0 search-form">
<div class="input-group">
<input class="form-control" type="search" placeholder="Search" name='q' aria-label="Search" value='{{ request.GET.q }}'>
<span class='input-group-btn'>
<button class="btn btn-outline-success" type="submit">Search</button>
</span>
</div>
</form>
As well, here's my view.py backend:
from django.shortcuts import render
from django.views.generic import ListView
from products.models import Product
from django.core.paginator import Paginator
class SearchProductView(ListView):
#PROBLEM WITH PAGINATION IN THE SEarch function and view
#https://stackoverflow.com/questions/48436649/django-pagination-page-not-found?rq=1
#https://www.youtube.com/watch?v=acOktTcTVEQ
#https://www.youtube.com/watch?v=q-Pw7Le30qQ
#https://docs.djangoproject.com/en/3.1/topics/pagination/
#paginate_by = 6
template_name = "search/view.html"
def get_context_data(self, *args, **kwargs):
context = super(SearchProductView, self).get_context_data(*args, **kwargs)
context['query'] = self.request.GET.get('q')
return context
def get_queryset(self, *args, **kwargs):
request = self.request
method_dict = request.GET
query = method_dict.get('q', None) #method_dict['q']
if query is not None:
return Product.objects.search(query).order_by('title')
return Product.objects.filter(featured=True).order_by('title')
'''
__icontains = field contains this
__iexact = field is exactly this
'''
Finally, here are my urls:
from django.conf.urls import url
from .views import (
SearchProductView
)
urlpatterns = [
url(r'^$', SearchProductView.as_view(), name='query'),
]

why when I click a different user returns me back to the current request user?

sorry, I had to take some screenshots to explains what is going on with me. now, I have much profile that has many different users and when I log in with one of it I'll assume the username is: medoabdin like you find on the screenshot now (medoabdin) and the name of it is (Origin) for me is a current user request. so, now I have also many different questions created by the different users, and when I want to enter any other profile let's suppose the user is (abdelhamedabdin) by current request user it returns me back to the current request (medoabdin) and not returns me back to abdelhamedabdin.
however, when I check the link URL I find the link is correct and when I log in with (abdelhamedabdin) user I see the same thing occurs to me against (medoabdin) so, can anyone tell me what is going on guys?
these are screenshots:
current request (medoabdin),
several questions,
show the link url for different users,
accounts/profile.html
{% extends 'base.html' %}
{% block title %} {{ user.first_name }} {{ user.last_name }} Profile {% endblock %}
{% block body %}
<!-- User Profile Section -->
{% if user.is_authenticated %}
<div class="profile">
<div class="container-fluid">
<div class="col-md-1">
<div class="thumbnail">
<div class="row">
<div class="col-xs-12">
<!-- Profile View Section -->
<div class="logo-image text-center">
{% if user.userprofile.logo %}
<div class="my-image">
{% if request.user.username == user.userprofile.slug %}
<a href="{% url 'accounts:user_image' user.userprofile.slug %}">
<img class="img-responsive" src="{{ user.userprofile.logo.url }}">
</a>
<span>
<a href="{% url 'accounts:add_avatar' user.userprofile.slug %}" class="fa fa-camera fa-1x text-center">
<p>Upload Image</p>
</a>
</span>
{% endif %}
</div>
{% else %}
{% load static %}
<div class="my-image">
<img class="img-responsive img-thumbnail" src="{% static 'index/images/default-logo.jpg' %}">
<span>
<a href="{% url 'accounts:add_avatar' user.userprofile.slug %}" class="fa fa-camera fa-1x text-center">
<p>Upload Image</p>
</a>
</span>
</div>
{% endif %}
{% if user.first_name != '' and user.last_name != '' %}
<h4>{{ user.first_name }} {{ user.last_name }}</h4>
{% else %}
<h4>User Profile</h4>
{% endif %}
</div>
</div>
<div class="col-xs-12">
<div class="caption">
<ul class="nav nav-pills nav-stacked">
<li role="presentation" class="active">Overview</li>
<li role="presentation" class="">Personal Information</li>
<li role="presentation" class="">Skills</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<!-- Information Sections -->
<div class="col-md-8 col-md-offset-3 information">
<div class="overview show" id="overview">
<h2 class="line">Overview</h2>
<p class="lead">{{ user.userprofile.overview }}</p>
<a data-placement="bottom" title="update overview" class="fa fa-edit" data-toggle="modal" data-tooltip="tooltip" data-target=".overview_info"></a>
</div>
<div class="personal-info" id="personal-information">
<h2 class="line">Personal Information</h2>
<p class="lead">City: {{ user.userprofile.city }}</p>
<p class="lead">Phone Number: 0{{ user.userprofile.phone }}</p>
<p class="lead">Sex: {{ user.userprofile.sex }}</p>
<a data-placement="bottom" title="update personal information" class="fa fa-edit" data-toggle="modal" data-tooltip="tooltip" data-target=".personal_info"></a>
</div>
<div class="skill" id="my-skills">
<h2 class="line">Skills:</h2>
<p class="lead">{{ user.userprofile.skill }}</p>
<a data-placement="bottom" title="update skills" class="fa fa-edit" data-toggle="modal" data-tooltip="tooltip" data-target=".skills"></a>
</div>
</div>
<!-- get all questions -->
{% if user_prof.userasking_set.all %}
<div class="col-md-8 col-md-offset-3 user_questions">
<h2 class="line">All Questions You Asked</h2>
{% for questions in user_prof.userasking_set.all %}
<p>{{ questions.title }}</p>
{% endfor %}
</div>
{% endif %}
<!-- get favourites -->
{% if get_favourite %}
<div class="col-md-8 col-md-offset-3 user_questions">
<h2 class="line">Favourites</h2>
{% for fav in get_favourite %}
<p>{{ fav.title }}</p>
{% endfor %}
</div>
{% endif %}
</div>
{% include 'accounts/information_form.html' %}
</div>
{% include 'base_footer.html' %}
{% endif %}
{% endblock %}
accounts/views.py
#method_decorator(login_required, name='dispatch')
# view profile page
class ViewProfile(UpdateView):
queryset = UserProfile.objects.all()
template_name = 'accounts/profile.html'
form_class = UpdateInfoForm
slug_field = 'slug'
slug_url_kwarg = 'user_slug'
def get_success_url(self):
return reverse_lazy('accounts:view_profile', kwargs={'user_slug': self.request.user.userprofile.slug})
def get_context_data(self, **kwargs):
self.request.session['switch_comment'] = False
context = super().get_context_data(**kwargs)
user_prof = UserProfile.objects.get(user=self.request.user)
context['user_prof'] = user_prof
context['get_favourite'] = User.objects.get(username=self.request.user.username).favorite.all()
return context
def form_valid(self, form):
form.instance.user_slug = self.request.user.userprofile.slug
self.object = form.save()
return super().form_valid(form)
community/views.py
# List all questions + search
class UserQuestions(ListView):
template_name = 'community/user_questions.html'
context_object_name = 'all_objects'
queryset = UserAsking
def get_context_data(self, object_list=queryset, **kwargs):
context = super().get_context_data(**kwargs)
# paginator
context['all_objects'] = UserAsking.objects.all()
paginator = Paginator(context['all_objects'], 5)
page_number = self.request.GET.get('page_number')
context['all_objects'] = paginator.get_page(page_number)
# search
context['query'] = self.request.GET.get("query", '')
if context['query']:
all_objects = UserAsking.objects.all().order_by('-date')
context['all_objects'] = all_objects.filter(
Q(title__contains=self.request.GET['query']) |
Q(question__contains=self.request.GET['query']) |
Q(field__contains=self.request.GET['query'])
)
return context
community/user_questions.py
{% extends 'base.html' %}
{% block title %} All Questions That People Asked {% endblock %}
{% block body %}
{% if request.user.is_authenticated %}
<div class="all-questions">
<div class="container">
<div class="fl-left hidden-sm hidden-xs">
<h2>All Questions</h2>
</div>
<div class="fl-right hidden-sm hidden-xs">
Ask Question
</div>
<div class="clear"></div>
<div class="row">
<div class="add-q">
<div class="col-sm-12 visible-sm-block visible-xs-block">
<h2>All Questions</h2>
</div>
<div class="col-sm-12 visible-sm-block visible-xs-block">
Ask Question
</div>
</div>
{% if all_objects %}
<div class="col-sm-12">
<div class="questions">
{% for post in all_objects %}
<div class="q_section">
<a class="text-primary title" href="{% url 'community:question_view' post.ask_slug %}">{{ post.title }}</a>
<p class="field">{{ post.field }}</p>
<div class="info fl-right">
<span class="time">{{ post.date }}</span> |
<a href="{% url 'accounts:view_profile' post.userprofile.slug %}" style="font-size:14px">
{% if post.userprofile.user.first_name != '' %}
{{ post.userprofile.user.first_name }}
{% else %}
User
{% endif %}
<img class="logo-image" style="width:25px;height: 25px" src="
{% if request.user.userprofile.logo %}
{{ request.user.userprofile.logo.url }}
{% else %}
{% load static %}
{% static 'index/images/default-logo.jpg' %}
{% endif %}
">
</a>
</div>
<div class="">
<!--a class="btn btn-primary btn-lg" href="{# {% url 'community:delete_post' post.id %} #}">
<i class="fa fa-trash x2"></i>
</a-->
</div>
</div>
{% endfor %}
</div>
</div>
{% else %}
<h2 class="text-center text-info">No Questions</h2>
{% endif %}
</div>
<!-- Pagination -->
{% if all_objects %}
<div class="pagination">
<span class="step-links">
{% if all_objects.has_previous %}
« first
previous
{% endif %}
<span class="current">
Page {{ all_objects.number }} of {{ all_objects.paginator.num_pages }}.
</span>
{% if all_objects.has_next %}
next
last »
{% endif %}
</span>
</div>
{% endif %}
</div>
</div>
{% include 'base_footer.html' %}
{% endif %}
{% endblock %}

Django 1.3 Pagination Not Showing Page Links and Showing all Records

I'm trying to set up Django Pagination in Django 1.3, It doesn't seem to be working, as I have over 5 records returned and the links are messed up
View:
def directory(request, bought_in_control_panel_id):
listings = Directory.objects.all().exclude(visible=False).order_by('rank', 'company__name').filter(company__uuid__in=local_uuids)
paginator = Paginator(listings, 5) # Show 25 contacts per page
# Make sure page request is an int. If not, deliver first page.
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
# If page request (9999) is out of range, deliver last page of results.
try:
page_listings = paginator.page(page)
except (EmptyPage, InvalidPage):
page_listings = paginator.page(paginator.num_pages)
return share.output_page(request, 'directory/directory.html', {'listings': page_listings, 'bought_in_control_panel_id': bought_in_control_panel_id})
Template:
{% block main %}
<link href="/media/css/bootstrap.min.css" rel="stylesheet">
<div class="container-fluid">
<div class="dbx-group">
<div class="dbx-box">
<h3 class="dbx-handle"><div class="tools"></div> <img src="/media/img/32x32/addressbook.png" style="position:absolute; margin-top:-16px;"><div class="title">Online Suppliers listings {% jms_help_link user 'directory_listings' %}</div></h3>
<h3 class="dbx-handle"><div class="tools"></div> <a title="Change region" href="{% url change_flag bought_in_control_panel_id iso %}"><img src="/media/img/flags-iso/48/{{ iso|lower }}.png" alt="Change region" align="right" style="margin-top:-45px;"></a><div class="title"></div></h3>
<ul class="dbx-content" width=98%>
{% if listings %}
{% for listing in listings %}
{% if listing.visible %}
<div class="well well-small" onclick="window.location.href = '{% url view_directory listing.uuid bought_in_control_panel_id %}'" style="cursor:pointer;">
<div class="row-fluid">
<div class="span12">
<a style="display:block" href="{% url view_directory listing.uuid bought_in_control_panel_id %}">
<h4>{{ listing.company.name }}</h4>
</a>
<div class="row-fluid">
<div class="span10">
<blockquote>{{listing.description|truncatewords:30}}</blockquote>
<p>Click for more info and downloads</p>
</div>
<div class="span2">
<img src="{% url view_banner listing.uuid %}" alt="">
</div>
</div>
</div>
</div>
</div>
{% endif %}
{% endfor %}
<div class="pagination">
<span class="step-links">
{% if listings.has_previous %}
previous
{% endif %}
<span class="current">
Page {{ listings.number }} of {{ listings.paginator.num_pages }}.
</span>
{% if listings.has_next %}
next
{% endif %}
</span>
</div>
{% else %}
<p align="center"><b>No listings!</b></p>
{% endif %}
<div style="clear:both;"></div>
</div>
</div>
</div>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="/media/js/bootstrap.min.js"></script>
{% endblock %}
share.output_page:
def output_page(request, htmlpage, dct={}):
t = loader.get_template(htmlpage)
c = RequestContext(request,dct)
return http.HttpResponse(t.render(c))
In Django 1.3 you need to use:
{% for listing in listings.object_list %}
It's changed in Django 1.4.