程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[quantitative investment system]django realizes screening and paging from the database

編輯:Python

**

Django Filtering data classification can only jump to the first page , Page 2 no data .

**
1.models.py Creating models

class User(models.Model):
uname= models.CharField(max_length=20)
uEmail= models.CharField(max_length=35)
uphone= models.CharField(max_length=15)

2.views.py Filter data from the database

 if request.method == 'POST':
name = request.POST.get('code')
else:
name = request.GET.get('code')
UserList = User.objects.filter(uphone=name).order_by()

3. Pager

 paginator = Paginator(UserList,2) # 3 posts in each page
page = request.GET.get('page')
try:
pagedata = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer deliver the first page
pagedata = paginator.page(1)
except EmptyPage:
# # If page is out of range deliver last page of results
pagedata = paginator.page(paginator.num_pages)

4. To transfer data

 return (render(request,'Qt15606/students.html',{
'name':name,'page': pagedata,'pagedata': pagedata}))

5. Front end interface students.html

<div class="pagination">
<span class="step-links">
{
% if page.has_previous %}
<a  href="?page=1&code={
{name}}" > first page </a>
<a class="btn btn-primary btn-lg active" href="?page={
{page.previous_page_number}}&code={
{name}}"> The previous page </a>
{
% endif %}
<span  class="current">
The first {
{
 page.number}} page ··· common {
{
 page.paginator.num_pages}} page
</span>
{
% if page.has_next %}
<a class="btn btn-primary btn-lg active" href="?page={
{page.next_page_number }}&code={
{name}}"> The next page </a>
<a class="btn btn-primary btn-lg active" href="?page={
{page.paginator.num_pages}}&code={
{name}}"> The last page </a>
{
% endif %}
</span>
</div>

The most important step is to add filter conditions to the links .href="?page={ {page.next_page_number }}&code={ {name}}"


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved