我一直在Django上获取'WSGIRequest'对象没有属性'Get' [英] I keep getting 'WSGIRequest' object has no attribute 'Get' on django
问题描述
我正在尝试构建一些用于练习目的的木板"应用程序.我目前停留在页面上,如果尝试加载分页器模板,则会出现错误.
I'm trying to build a little "boards" app for practicing purposes. I'm currently stuck on a page, where a error occurs if I try to load a paginator template.
错误回溯如下所示:
AttributeError at /board/2/
'WSGIRequest' object has no attribute 'Get'
Request Method: GET
Request URL: http://192.168.56.101:8000/board/2/
Django Version: 1.7.6
Exception Type: AttributeError
Exception Value:
'WSGIRequest' object has no attribute 'Get'
Exception Location: /home/web/workspace/simpleboard/board/views.py in read_board, line 38
Python Executable: /home/web/venv/bin/python
Python Version: 3.4.2
Python Path:
['/home/web/workspace/simpleboard',
'/home/web/venv/lib/python34.zip',
'/home/web/venv/lib/python3.4',
'/home/web/venv/lib/python3.4/plat-linux',
'/home/web/venv/lib/python3.4/lib-dynload',
'/home/web/.pyenv/versions/3.4.2/lib/python3.4',
'/home/web/.pyenv/versions/3.4.2/lib/python3.4/plat-linux',
'/home/web/venv/lib/python3.4/site-packages']
Traceback Switch to copy-and-paste view
/home/web/venv/lib/python3.4/site-packages/django/core/handlers/base.py in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs) ...
▶ Local vars
/home/web/workspace/simpleboard/board/views.py in read_board
page = request.Get.get("page") ...
▶ Local vars
观看次数:
def read_board(request, board_id):
board = get_object_or_404(Board, id=board_id)
article_list = board.article_set.order_by("-written_date")
paginator = Paginator(article_list, 5)
page = request.Get.get("page") <--error here, apparently.
try:
articles = paginator.page(page)
except PageNotAnInteger:
articles = paginator.page(1)
except EmptyPage:
articles = paginator.page(paginator.num_pages)
context = {
"board" : board,
"articles" : articles,
"pages" : paginator.page_range
}
return render(request, "board.html", context)
谢谢.
PS:Tab键在stackoverflow上不起作用,因此我不得不缩进空格.当我按Tab时,它跳到下面的标签"框.有人知道问题出在哪里吗?据我所记得,我上次工作得很好.(顺便说一下,我在Mac OS上.)
PS: tab key is not working on stackoverflow, so I had to indent with spaces instead. When I press tab, it jumps to "tags" box underneath. Does anyone know what the problem is? As far as I can remember, I worked fine last time. (I'm on Mac OS by the way.)
推荐答案
您输错了 GET
.使用:
page = request.GET.get("page")
请阅读Django上的"请求和响应对象"文章文档.
Please read "Request and response objects" article on Django Docs.
这篇关于我一直在Django上获取'WSGIRequest'对象没有属性'Get'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!