0
私はPythonとDjangoを使ってムービーWebアプリケーションを作成していますが、実際にはわからないエラーが出る検索機能があります。'set'オブジェクトに 'session'属性がありません
ERROR
[16/May/2016 16:22:05] ERROR [django.request:284] Internal Server Error: /movies/search/
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\user\git\DjangoServer\movies\views.py", line 157, in search
set(filteredresolution)
File "C:\Users\user\git\DjangoServer\movies\views.py", line 38, in list
request.session['nextpage'] = reverse('movies:list', kwargs={'page': page})
AttributeError: 'set' object has no attribute 'session'
映画/ views.py検索機能
def search(request, keyword='', resolution='all'):
if request.POST:
request.session['nextpage'] = reverse('movies:search', kwargs={
'keyword': request.POST.get('keyword'),
'resolution': request.POST.get('resolution')})
else:
request.session['nextpage'] = reverse('movies:search', kwargs={
'keyword': keyword,
'resolution': resolution})
searchresult = []
resolutions = Resolution.objects.all().order_by('name')
if request.POST:
keyword = request.POST.get('keyword')
resolutionid = request.POST.get('resolution')
else:
keyword = keyword
resolutionid = resolution
filteredkeyword = []
filteredresolution = []
filteredall = Movie.objects.all()
if keyword != '':
filteredkeyword = Movie.objects.filter(title_en__icontains=keyword)
else:
filteredkeyword = filteredall
if resolutionid != 'all':
storedmovies = StoredMovie.objects.filter(resolution__id=int(resolutionid))
for stored in storedmovies:
filteredresolution.append(stored.movie)
else:
filteredresolution = filteredall
searchresult = list(
set(filteredkeyword) &
set(filteredresolution)
)
return render(request, 'movies/search.html', {
'movies': searchresult,
'lang': lang,
'countresult': len(searchresult) #ez mire is?
})
私は一種-の私は2リストのセグメントを作成どこにエラーがあることを理解しますが、セッションがありませんそこ。 私は以下の通りですリストページから、それを呼び出す:list
というビューを持つことにより
def list(request, page=1):
request.session['nextpage'] = reverse('movies:list', kwargs={'page': page})
lang = request.session.get('language', 'failed')
if lang == 'failed' or lang not in supported_langs :
return redirect('movies:language')
movie_list = Movie.objects.all().order_by('-added')
resolutions = Resolution.objects.all().order_by('name')
paginator = Paginator(movie_list, 20) # Show 20 contacts per page
#page = request.GET.get('page')
try:
movies = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
movies = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
movies = paginator.page(paginator.num_pages)
return render(request, 'movies/list.html', {
'movies': movies,
'lang': lang,
'resolutions': resolutions,
})
あなたが 'searchresult = list(set(...)&...)'を実行したときに、組み込みの 'list'関数またはあなた自身のものを使うことを意味しますか? –
私は組み込みのものを使用するつもりだった – MorRich