gpt4 book ai didi

python - 我不断收到 'WSGIRequest' object has no attribute 'Get' on django

转载 作者:太空宇宙 更新时间:2023-11-03 12:16:03 29 4
gpt4 key购买 nike

我正在尝试构建一个用于练习的小“板”应用程序。我目前卡在一个页面上,如果我尝试加载分页器模板会发生错误。

错误回溯如下所示:

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 上不起作用,所以我不得不用空格缩进。当我按下标签时,它会跳转到下面的“标签”框。有谁知道问题出在哪里?据我所知,我上次工作得很好。 (顺便说一下,我使用的是 Mac 操作系统。)

最佳答案

您打印错误了 GET。使用:

page = request.GET.get("page")

请阅读 Django Docs 上的“Request and response objects”文章。

关于python - 我不断收到 'WSGIRequest' object has no attribute 'Get' on django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32808106/

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