gpt4 book ai didi

python - “WSGIRequest”对象没有属性 'update'

转载 作者:行者123 更新时间:2023-12-01 05:11:46 26 4
gpt4 key购买 nike

我已经针对类似问题尝试过一些解决方案,但没有一个有效:

'WSGIRequest' object has no attribute 'session'

'WSGIRequest' object has no attribute 'facebook'

我正在构建一个搜索页面,如下所示:

View .py

def search(request):
if 'query' in request.GET and request.GET['query']:
q = request.GET['query']
ct = Product.objects.filter(Q(name__icontains=q) | Q(desc__icontains=q) | Q(category__icontains=q))
count = ct
paginate = Paginator(ct, 10)
page = request.GET.get('page')
try:
ct = paginate.page(page)
except PageNotAnInteger:
ct = paginate.page(1)
except EmptyPage:
ct = paginate.page(paginate.num_pages)
dictionary = {'results': ct, 'count': count, 'query': q, }
return render_to_response('search.html', dictionary, request)
else:
content = {'contentnotfound': 'Hi, you did not search for anything. Please go back or use the search box above.'}
return render(request, 'search.html', content)

完整的回溯是:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/search?query=abc&submit=Submit

Django Version: 1.6.4
Python Version: 2.7.3
Installed Applications:
('django_admin_bootstrapped.bootstrap3',
'django_admin_bootstrapped',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Abstract',
'south',
'djrill',
'storages',
's3direct')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "/home/siddharth/AbstractIndia/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/siddharth/AbstractIndia/Abstract/views.py" in search
39. return render_to_response('search.html', dictionary, request)
File "/home/siddharth/AbstractIndia/venv/local/lib/python2.7/site-packages/django/shortcuts/__init__.py" in render_to_response
29. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/home/siddharth/AbstractIndia/venv/local/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
167. context_instance.update(dictionary)

Exception Type: AttributeError at /search
Exception Value: 'WSGIRequest' object has no attribute 'update'

urls.py如下:

 url(r'^search$', views.search, name='search'),

我之前在另一个项目中做过同样的事情,而且效果很好。

最佳答案

return render_to_response('search.html', dictionary, request)

您将请求作为上下文实例传递,而您应该传递 django.template.Context 的实例(尽管您可能想使用其子类 RequestContext )。

关于python - “WSGIRequest”对象没有属性 'update',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24082248/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com