【发布时间】:2014-10-12 01:40:04
【问题描述】:
我正在开发一个基于 Django==1.5.7 的网站
我需要在我的应用程序中对表格的ListView 进行分页。
这是我正在使用的代码
在models.py上:
class UsuarioFidetel(models.Model):
"""
Modelo de usuario fidetel
"""
usuario = models.CharField(max_length=30)
id_usuario = models.IntegerField()
nombre = models.CharField(max_length=255, null=True)
apellido = models.CharField(max_length=255, null=True)
tipo_cedula = models.CharField(max_length=1, null=True)
cedula = models.CharField(max_length=9, null=True)
fecha_nacimiento = models.DateField(null=True, blank=True)
sexo = models.CharField(max_length=1, null=True)
correo = models.EmailField(max_length=254, null=True)
estado_civil = models.CharField(max_length=1, null=True)
def __unicode__(self):
return self.nombre
在views.py上:
class UsarioList(ListView):
model = UsuarioFidetel
template_name = 'all_list.html'
在 urls.py 上:
url(r'^usario/$', UsarioList.as_view(model=UsuarioFidetel, paginate_by=2)),
注意 url 的 paginate_by 属性,这工作得很好,但是当我转到第二页或第一页之外的任何页面时,它会抛出此错误:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:9001/usario?page=2
一切正常,但我认为这将通过模板块内的页面,没有重大错误,无法弄清楚这里有什么问题,也许我需要在 url 上使用正则表达式?
有什么想法吗?
提前致谢!
【问题讨论】:
标签: python regex django pagination