Environment:
Request Method: GET
Request URL: http://www.qiuqingyu.cn/cnki_spider/todolist/
Django Version: 1.9
Python Version: 3.6.0
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'pagination',
'myapp']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'myapp.middleware.CheckSoureMiddware']
>
> Traceback:
File "/root/anaconda3/lib/python3.6/site-packages/django/template/utils.py" in __getitem__
86. return self._engines[alias]
During handling of the above exception ('django'), another exception occurred:
File "/root/anaconda3/lib/python3.6/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/root/anaconda3/lib/python3.6/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "./myapp/views.py" in todolist
29. return render(request, 'todolist.html', context=locals())
File "/root/anaconda3/lib/python3.6/site-packages/django/shortcuts.py" in render
67. template_name, context, request=request, using=using)
File "/root/anaconda3/lib/python3.6/site-packages/django/template/loader.py" in render_to_string
96. template = get_template(template_name, using=using)
File "/root/anaconda3/lib/python3.6/site-packages/django/template/loader.py" in get_template
26. engines = _engine_list(using)
File "/root/anaconda3/lib/python3.6/site-packages/django/template/loader.py" in _engine_list
143. return engines.all() if using is None else [engines[using]]
File "/root/anaconda3/lib/python3.6/site-packages/django/template/utils.py" in all
110. return [self[alias] for alias in self]
File "/root/anaconda3/lib/python3.6/site-packages/django/template/utils.py" in <listcomp>
110. return [self[alias] for alias in self]
File "/root/anaconda3/lib/python3.6/site-packages/django/template/utils.py" in __getitem__
101. engine = engine_cls(params)
File "/root/anaconda3/lib/python3.6/site-packages/django/template/backends/django.py" in __init__
31. options['libraries'] = self.get_templatetag_libraries(libraries)
File "/root/anaconda3/lib/python3.6/site-packages/django/template/backends/django.py" in get_templatetag_libraries
49. libraries = get_installed_libraries()
File "/root/anaconda3/lib/python3.6/site-packages/django/template/backends/django.py" in get_installed_libraries
131. for name in get_package_libraries(pkg):
File "/root/anaconda3/lib/python3.6/site-packages/django/template/backends/django.py" in get_package_libraries
144. module = import_module(entry[1])
File "/root/anaconda3/lib/python3.6/importlib/__init__.py" in import_module
126. return _bootstrap._gcd_import(name[level:], package, level)
Exception Type: SyntaxError at /cnki_spider/todolist/
Exception Value: invalid syntax (pagination_tags.py, line 225)
誰かこの質問がありましたか?どうすれば修正できますか? CentOSでこれを満たしました、djangoは1.9、私はuwsgiを使用しました Pythonは3.6 誰かこの質問がありましたか?どうすれば修正できますか? 私はCentOSでこれを満たし、djangoは1.9、私はuwsgiを使用しました Pythonは3.6です ありがとう!djangoが無効な構文(pagination_tags.py、行225)
views.pyはここにある:
import os
from django.http import HttpResponse, HttpResponseRedirect
from django.http import StreamingHttpResponse
from django.shortcuts import render, render_to_response
from myapp.forms import TodolistaddForm
from myapp.models import Todolist
import datetime
from django.core.paginator import Paginator
from django.core.paginator import EmptyPage
from django.core.paginator import PageNotAnInteger
import datetime
from .tasks import cnki_spider
# Create your views here.
def todolist(request):
todolist_lists = Todolist.objects.order_by("-id")
limit = 10
paginator = Paginator(todolist_lists, limit)
page = request.GET.get('page')
try:
todolist_lists = paginator.page(page)
except PageNotAnInteger:
todolist_lists = paginator.page(1)
except EmptyPage:
todolist_lists = paginator.page(paginator.num_pages)
return render(request, 'todolist.html', locals()) #error!!!!!!!!
def add_todolist(request):
if request.method == "POST":
body = request.POST['body']
add_date = datetime.datetime.now()
tag_type = 0
print(add_date)
print(body)
#add.delay(5,6)
cnki_spider.delay(body)
if body:
Todolist.objects.create(
body=body,
add_date=add_date,
tag_type=tag_type,
)
return HttpResponseRedirect('/todolist/')
else:
return HttpResponseRedirect('/todolist/')
def del_todolist(request):
rowid = request.GET['rowid']
body = Todolist.objects.filter(id=rowid)[0].body
Todolist.objects.filter(id=rowid).delete()
the_file_name = "data_out_" + body + ".xls"
os.remove(the_file_name)
print(the_file_name)
os.remove('data-detail-'+ body +'.txt')
return HttpResponse('{"code":0}')
def edit_todolist(request):
rowid = request.POST['rowid']
todolist_id = Todolist.objects.get(id=rowid)
todolist_id.body = request.POST['body']
todolist_id.save()
return HttpResponseRedirect('/todolist/')
def download_todolist(request):
rowid = request.POST['rowid']
todolist_id = Todolist.objects.get(id=rowid)
todolist_id.body = request.POST['body']
def readFile(fn, buf_size=262144):#大文件下载,设定缓存大小
f = open(fn, "rb")
while True:#循环读取
c = f.read(buf_size)
if c:
yield c
else:
break
f.close()
the_file_name = "data_out_"+todolist_id.body+".xls"
response = StreamingHttpResponse(readFile(the_file_name))
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;filename="{0}"'.format(the_file_name)
return response
def chk_todolist(request):
rowid = request.GET['rowid']
todolist_id = Todolist.objects.get(id=rowid)
todolist_id.tag_type = request.GET['status']
todolist_id.save()
return HttpResponse('{"code":0}')
エラーは 'pagination_tags.py'にあります...それの関連する部分を表示/デバッグするのに役立ちます。何を試しましたか? – Sayse
あなたが特定のファイルにエラーがあることがわかっているときは、私たちが助けることができるように投稿してください。 – Exprator
それはWindows10で正しく動作することができますが、CentOSで動作しない理由はわかりません。 –