페이지 1

1367 단어
urls.py
from django.conf.urls import url
from django.contrib import admin
from app01 import views
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^index/', views.index, name='index'),
]

views.py
# encoding=utf-8
from django.shortcuts import render

# Create your views here.

def index(request):
    #    ,     
    a_list = [i for i in range(1, 105)]

    #     ,          ,    int
    current_page = request.GET.get('p', 1)
    current_page = int(current_page)

    #    
    #data = a_list[:10]
    #data = a_list[20: 30]

    #    10   ,    current_page    ,  10   
    start = (current_page-1) * 10
    end = current_page * 10
    data = a_list[start: end]

    return render(request, 'index.html', {'data': data})

template



    
    


<ul>
    {% for d in data %}
        <li>{{ d }}</li>
    {% endfor %}
</ul>


</code></pre> 
 <blockquote> 
  <p>  127.0.0.1:8000/index/?p=1<br/> 127.0.0.1:8000/index/?p=2<br/> 127.0.0.1:8000/index/?p=3<br/> .....<br/>       ,       。</p> 
 </blockquote> 
</article>
                            </div>
                        </div>

좋은 웹페이지 즐겨찾기