- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在使用教程进行 django 项目,并且收到了此消息。当我单击单选框进行投票时,管理中的计数增加,但网站显示错误消息而不是加载模板。似乎 model.py 中有问题,所以我添加了它。
TypeError at /polls/3/vote/
reverse() takes no keyword arguments
Request Method: POST
Request URL: http://127.0.0.1:8000/polls/3/vote/
Django Version: 1.10.5
Exception Type: TypeError
Exception Value: reverse() takes no keyword arguments
Exception Location: C:\Users\jeon hyun joo\workspace\ch3\polls\views.py in vote, line 33
Python Executable: C:\Python27\python.exe
Python Version: 2.7.13
Python Path:
['C:\\Users\\jeon hyun joo\\workspace\\ch3',
'C:\\Users\\jeon hyun joo\\workspace\\ch3',
'C:\\Python27\\DLLs',
'C:\\Python27\\lib',
'C:\\Python27\\lib\\lib-tk',
'C:\\Python27',
'C:\\Python27\\lib\\site-packages',
'C:\\Python27\\lib\\site-packages\\django-1.10.5-py2.7.egg',
'C:\\WINDOWS\\SYSTEM32\\python27.zip',
'C:\\Python27\\lib\\plat-win']
View .py
from audioop import reverse
from gc import get_objects
from django.http.response import HttpResponseRedirect
from django.shortcuts import render, get_object_or_404
from django.template.context_processors import request
from polls.models import Question, Choice
# Create your views here.
def index(request):
latest_question_list = Question.objects.all().order_by('-pub_date')[:5]
context = {'latest_question_list': latest_question_list}
return render(request, 'polls/index.html', context)
def detail(request, question_id):
question = get_object_or_404(Question, pk=question_id)
return render(request, 'polls/detail.html', { 'question' : question })
def vote(request, question_id):
question = get_object_or_404(Question, pk=question_id)
try:
selected_choice = question.choice_set.get(pk=request.POST['choice'])
except (KeyError, Choice.DoesNotExist):
return render(request, 'polls/detail.html', {
'question' : question,
'error_message' : "You didn't select a choice",
})
else:
selected_choice.votes += 1
selected_choice.save()
return HttpResponseRedirect(reverse('polls:results', args=(question.id,)))
def results(reqeust, question_id):
question = get_object_or_404(Question, pk=question_id)
return render(request, 'polls/results.html', { 'question' : question })
我添加了从 eclipse 控制台收到的消息
TypeError: reverse() takes no keyword arguments
[11/Feb/2017 16:50:30] "POST /polls/3/vote/ HTTP/1.1" 500 67663
最佳答案
您正在覆盖 django reverse方法与这行代码:
from audioop import reverse
要使用 django 的反向功能,您应该导入它:
from django.urls import reverse
如果您仍然需要 audioop 的反向,您可以使用 as
语法的同义词:
from audioop import reverse as audio_reverse
关于python - Django教程: TypeError at/polls/3/vote/reverse() takes no keyword arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42173580/
import csv import numpy as np from sklearn.svm import SVR import matplotlib.pyplot as plt dates = []
我在 ANTLRWorks 1.4 中有以下语法。我正在考虑在文本冒险游戏创建器中实现解析器的想法,其中用户将为他的游戏指定各种允许的命令。 grammar test; parse :
我有一个 .dat 文件,我首先想将其转换为 .csv 文件,然后根据时间绘制一些行,我的脚本如下: import pandas as pd import numpy as np from sys i
python 出现SyntaxError: non-keyword arg after keyword arg错误解决办法 前言:
我有一个我无法理解的问题,因此在删除按钮中,尝试在创建按钮后将其删除的地方,出现以下错误: Delete=Button(root,text='Delete',command=lambda : S.pa
我想将某个函数作为线程运行,但我得到了 SyntaxError: non-keyword arg after keyword arg 我不明白为什么: #!/usr/bin/env python im
我试图在 scrappy 中抓取多个页面,我的函数确实返回第一个起始网址,但我无法设法使蜘蛛的规则生效。 这是我到目前为止所拥有的: import scrapy from scrapy.contrib
我正在使用 emeditor,我试图从法语维基百科转储 .xml 文件(20GB,3.38 亿行,总共 480 万篇文章)中分离出大约 200 万篇包含 keyword3 的文章。我想将文本包含在 2
发布表如下所示: publications ============ id title etc ... 关键字表如下所示: keywords ======== id name etc ... keyw
我有这个功能: def crypting(self, client, access_token, client_id, client_secret, oauth_scope, redirect_uri
我正在学习 Rails,但在以下代码中出现语法错误 unexpected keyword else, expected keyword end,我不知道为什么。
我正在一个网站上工作,我必须在数据库中搜索根域上/之后的字符串。我在文档中找不到任何有关它的信息。我正在尝试使其与 Iron Router 一起使用,但任何其他建议都会起作用。 感谢您的帮助! 编辑:
我刚刚找到有关 apache solr 的信息,并且在我成功安装了带有 Tomcat 的 apache Solr 之后。然后我开始使用 Apache Solr 进行搜索。 但我对 Apache Sol
我是 Angular JS 新手。我无法弄清楚过滤器如何仅对对象中的名称起作用,而不是对对象中的电话键起作用。就好像我们在 ng-model 中仅使用关键字一样,它将过滤范围中定义的对象中的名称和电话
当我运行以下代码行时,我试图将按钮按下绑定(bind)到 Tkinter 中的函数 get = Button(root, lambda: ChangeColour(boxes[1][2], boxes
response = requests.post("http://api.bf3stats.com/pc/player/", data = player, opt) 在 python IDLE 中运行
这是我正在操作的更新查询。此处错误“set data = :updateValue”,数据是 Dynamo DB 的保留关键字。我想我应该在这里使用 update ExpressionAttribut
根据维基百科,二元运算符 ?:是 colloquially referred to as the Elvis operator due to its resemblance to an emotico
我知道 AND 词定义了二进制 and ...但什么定义了逻辑and ? 最佳答案 同一个字,AND , 也用于逻辑与。但是这两个输入值要AND推荐为格式良好的标志 ; 真和 假 由两个值表示,位全部
反引号运算符的固定性是什么? 例如在 Real World Haskell 的这段代码中: ghci> (1+) `fmap` [1,2,3] ++ [4,5,6] [2,3,4,4,5,6] 很明显
我是一名优秀的程序员,十分优秀!