python - Clean url in django app. without ?page=1 pattern -


i want have url pattern below pattern:

host:8000/archive/2/ 

i define page_kwarg in view still receive: host:8000/en/2

code form main url.py file:

url(_(r'^archive'), include('events.urls_archive', namespace='archive')), 

start edit1 , link form main site app:

<a href="{% url 'archive:list' %}" title="{% trans 'archive' %}">     {% trans 'archive' %} </a> 

end edit1

start edit2

this url in app urls_archive.py:

urlpatterns = [     url('^/(?p<page>\d+)/$', archivelistview.as_view(), name="list"),     url('^/(?p<slug>[-\w]+)/(?p<pk>\d+)$', archivedetailview.as_view(), name="detail"), ] 

end edit2

the code view:

class archivelistview(listview):     model = booking     queryset = booking.objects.filter(period__type='archive').order_by('-date_start')     paginate_by = 80     page_kwarg = 'page' 

here template code:

        {% if is_paginated %}             {% if page_obj.has_previous %}                 <a href="/{{ page_obj.previous_page_number }}" class="arrow left"><h4>previous</h4></a>             {% endif %}             <span class="arrow header"><h4>page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}</h4></span>             {% if page_obj.has_next %}                 <a href="/{{ page_obj.next_page_number }}" class="arrow right"><h4>next</h4></a>             {% endif %}         {% endif %} 

please provide help. thanks.

page_kwarg sets key page number passed in as. doesn't affect how used in page. reason, outputting directly /{{ page_obj.previous_page_number }}, resolves /2. should output in same format passed in:

?page={{ page_obj.previous_page_number}} 

edit

if want page number specified part of path arguments, should use url tag, other url:

{% url 'archive' page=page_obj.previous_page_number %} 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -