网址:
urlpatterns = patterns('',
# Examples:
url(r'^$', views.reports, name='reports'),
url(r'^(?P<did>\d+)/pdf/$', views.pdf),
url(r'^(?P<dated>\d+)/$',views.dated)
)
观点:
def dated(request,dated):
l=str(dated)
s=len(l)
if s==6:
a1=''
a2=l[:2]
a3=l[2:6]
p=freshh.objects.filter(expirydate__year=a3,expirydate__month=a2)
q=renewall.objects.filter(expirydate__year=a3,expirydate__month=a2)
r=enhancementt.objects.filter(expirydate__year=a3,expirydate__month=a2)
elif s==8:
a1=l[4:8]
a2=l[2:4]
a3=l[:2]
a=a1+'-'+a2+'-'+a3
p=freshh.objects.filter(expirydate__range=[a,a])
q=renewall.objects.filter(expirydate__range=[a,a])
q=enhancementt.objects.filter(expirydate__range=[a,a])
elif s==16:
a1=l[:2]
a2=l[2:4]
a3=l[4:8]
a4=l[8:10]
a5=l[10:12]
a6=l[12:16]
p=freshh.objects.filter(expirydate__range=[a3+'-'+a2+'-'+a1,a6+'-'+a5+'-'+a4])
q=renewall.objects.filter(expirydate__range=[a3+'-'+a2+'-'+a1,a6+'-'+a5+'-'+a4])
r=enhancementt.objects.filter(expirydate__range=[a3+'-'+a2+'-'+a1,a6+'-'+a5+'-'+a4])
else:
p=None
q=None
r=None
template = loader.get_template('templates/files.html')
context = RequestContext(request,{'p':p,'q':q,'r':r,})
return HttpResponse(template.render(context))
我需要根据日期以不同的方式查询数据,格式可能是032014; 02032014; 01022014,20022014。当我尝试使用网址'localhost / files / 032014 /'时,显示
DoesNotExist at /files/032014/
files matching query does not exist.
Request Method: GET
Request URL: localhost/files/032014/
Django Version: 1.6
Exception Type: DoesNotExist
Exception Value:
files matching query does not exist.
Exception Location: C:\Python27\lib\site-packages\django\db\models\query.py in get, line 307
Python Executable: C:\Python27\python.exe
但昨天,同一个查询产生了结果