我有一个Django项目,在其中一个网页上,我想为一个项目收集一些信息。你知道吗
其中一个字段有一个下拉列表,用户可以从中选择参与项目的团队成员的姓名。此下拉列表有许多预定义的选项,还提供了选择“其他”的选项。你知道吗
如果用户选择“其他”,“下拉列表”字段变为“文本框”,用户可以键入要选择的人的姓名。当他们开始键入时,将根据他们迄今为止键入的字母查询数据库,并在文本框下方显示可用选项列表(与键入的字母匹配)。例如,如果用户键入了“D”,则将显示的可用选项列表可能包括:“Dan”、“Dave”、“Debbie”,但如果用户键入了“Da”,则将显示的可用选项列表将仅包括:“Dan”和“Dave”。你知道吗
当用户第一次在项目上加载此页时,“name”字段为空。当我开始在该字段中键入,并从显示的可用选项列表中选择一个选项时,浏览器控制台会显示一个错误,该错误显示:
jquery-2.2.2.min.js:4 POST http://localhost:8000/projects/5915/submit_3_5_ajax/ 500 (Internal Server Error)
我认为这可能意味着我使用了错误的方法,但是我尝试同时使用了Get
&;Post
,它们在浏览器控制台中都给出了相同的错误。。。你知道吗
python控制台还显示此错误:
ValueError: invalid literal for int() with base 10: ''
[10/Nov/2016 14:05:38] "POST /projects/5915/submit_3_5_ajax/ HTTP/1.1" 500 21537
据我所知,异常发生在我的forms.py
文件的form类中的某个地方:
class InfoForm(ValidatedForm):
...
def __init__(self, *args, **kwargs):
...
try:
who_will_organise = project.assigned.get(role=Role.O).employee.first_name + project.assigned.get(role=Role.O).employee.surname[0] # I just want to get the first character of the surname here...
except ObjectDoesNotExist: who_will_organise = None
...
def save(self, commit=True):
...
if data['who_will_organise']:
...
else:
# The print statements I'm seeing in the console would indicate that this is where the exception is being thrown...
who_will_organise = Employee.objects.get(id=data['who_will_organise'])
try:
...
except ...
...
...
return ...
页面的URL为:
url(r'^(?P<project_id>\d+)/survey/$', views.survey, name='survey'),
它调用的view
定义为:
def survey(request, project_id):
project = Project.objects.get(id=project_id)
survey = Survey.objects.get_or_create(project=project)[0]
context = {
'project': project,
'survey_form': SurveyInformationForm(instance=survey),
}
return render(request, 'projects/survey.html', context)
我的浏览器控制台显示以下错误消息:
POST http://localhost:8000/projects/5915/submit_3_5_ajax/ 500 (Internal Server Error)
autosave_form.js:122 FAIL: (){return f&&(c&&!b&&(h=f.length-1,g.push(c)),function d(b){n.each(b,function(b,c){n.isFunction(c)?a.unique&&j.has(c)||f.push(c):c&&c.length&&"string"!==n.type(c)&&d(c)})}(arguments),c&&!b&&i…
FAIL: (){return f&&(c&&!b&&(h=f.length-1,g.push(c)),function d(b){n.each(b,function(b,c){n.isFunction(c)?a.unique&&j.has(c)||f.push(c):c&&c.length&&"string"!==n.type(c)&&d(c)})}(arguments),c&&!b&&i…
在我运行Python服务器的命令行中的Python控制台中,我得到错误消息:
OperationalError: (1054, "Unknown column 'costing_addomit.group_id' in 'field list'")
[10/Nov/2016 15:01:24] "GET /projects/pipeline/ HTTP/1.1" 500 337434
有人能告诉我我做错了什么吗?你知道吗
看起来你在某处把一个字符串转换成Int。你知道吗
不久前我也遇到过类似的事情。一个堆栈跟踪和/或打印的东西你最好的朋友在这里。 我最好的猜测是,上面的代码是有效的,而问题实际上是在其他地方。你知道吗
检查要强制转换为int的位置,或者期望null不为null。问题可能就在那里。你知道吗
相关问题 更多 >
编程相关推荐