这是我的意见.py
from django.shortcuts import render
from site1.models import Flower
from django.core.paginator import Paginator
def home(request):
x = Flower.objects.all()
y = Paginator(x, 12)
pagex = y.page(1)
flowers = list(reversed(pagex.object_list))
c = []
for a in range(3):
c.append(a)
return render(request, 'home.html', {'s_list': flowers, 'links': c})
def home2(request, page):
x = Flower.objects.all()
y = Paginator(x, 12)
pagex = y.page(page)
flowers = list(reversed(pagex.object_list))
c = []
page = int(page)
if page == 1:
for a in range(1, 4):
c.append(a)
elif page == 2:
for a in range(1, 5):
c.append(a)
elif page == y.num_pages - 2:
for a in range(page - 2, page + 2):
c.append(a)
elif page == y.num_pages - 1:
for a in range(page - 2, page + 1):
c.append(a)
elif page == y.num_pages:
for a in range(page - 2, page):
c.append(a)
else:
for a in range(page - 2, page + 2):
c.append(a)
return render(request, 'home.html', {'s_list': flowers, 'links': c})
def type(request, type, page):
x = Flower.objects.all().filter(tip=type)
y = Paginator(x, 12)
pagex = y.page(page)
flowers = list(reversed(pagex.object_list))
c = []
page = int(page)
if page == 1:
for a in range(1, 4):
c.append(a)
elif page == 2:
for a in range(1, 5):
c.append(a)
elif page == y.num_pages - 2:
for a in range(page - 2, page + 2):
c.append(a)
elif page == y.num_pages - 1:
for a in range(page - 2, page + 1):
c.append(a)
elif page == y.num_pages:
for a in range(page - 2, page):
c.append(a)
else:
for a in range(page - 2, page + 2):
c.append(a)
return render(request, 'home.html', {'s_list': flowers, 'links': c})
这是 urls.py
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
url(r'^$', 'site1.views.home', name='home'),
url(r'^(\d+)$', 'site1.views.home2'),
url(r'^gul/(\d+)$', 'site1.views.type'),
# url(r'^mysite1/', include('mysite1.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls))
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += staticfiles_urlpatterns()
这是错误
TypeError at /gul/1
type() takes exactly 3 arguments (2 given)
Request Method: GET
Request URL: http://127.0.0.1:8000/gul/1
Django Version: 1.4.3
Exception Type: TypeError
异常值:
type() 正好采用 3 个参数(给定 2 个)异常位置:/Library/Python/2.7/site-packages/django/core/handlers/base.py in get_response,第 111 行
Python 可执行文件:/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python Python 版本:2.7.2
我不知道为什么会出现这个错误?我将 url 添加到 urls.py 我将链接添加到模板 home.html
我该如何解决这个问题?