Django:让分页的网址SEO友好

时间:2016-05-22 06:36:15

标签: python django pagination

我正试图让我的分页网址来自django一点点的SEO友好。而不是?page=current_page /page/current_page形式的东西。

所以在app/urls.py我做了以下事情:

url(r'^(?P<slug>[a-zA-Z0-9-_]+)/page/(?P<page>[0-9])+$', GalleryDetail.as_view(), name='galleries-view-gallery-paginator')

和我的app/templates/app/my_view.html

{% if page_obj.has_next %}       
  <a href="{% url 'galleries-view-gallery-paginator' page_obj.next_page_number %}">next</a>
{% endif %}

但我收到NoReverseMatch 错误

其他错误信息:Reverse for 'galleries-view-gallery-paginator' with arguments '(2,)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['gallery/(?P<slug>[a-zA-Z0-9-_]+)/page/(?P<page>[0-9])+$']

好吧。如何使用/page/current_page获取Django的网址?

1 个答案:

答案 0 :(得分:2)

网址public View getView(int position, View view, ViewGroup parent) { try { if(view == null) { view = LayoutInflater.from(context).inflate(R.layout.item_bill, parent, false); } Log.e("BillAdapter", "Position :: " + position); if(position == 0) { Log.e("BillAdapter", "Position zero. Not changing values...."); } else { Bill bill = items.get(position); Log.e("BillAdapter", position + " :: " + bill.toString()); TextView textDate = (TextView) view.findViewById(R.id.text_date); textDate.setText(bill.getDate()); TextView textPaidAmount = (TextView) view.findViewById(R.id.text_paid_amount); textPaidAmount.setText(String.format("%2.2f", bill.getPaidAmount())); } } catch (Exception ex) { Log.e("BillAdpater", Log.getStackTraceString(ex)); } return view; } 要求您传递2个参数:galleries-view-gallery-paginatorslug。由于您只传递页码,因此还需要slug:

page
相关问题