gpt4 book ai didi

python - Django 1.6 TypeError render_to_string() 得到关键字参数 'context_instance' 的多个值

转载 作者:太空宇宙 更新时间:2023-11-04 10:34:38 25 4
gpt4 key购买 nike

我试图在我的模板中显示与医生相关的所有等待时间。但是我得到了这个错误。我是 django 的新手,所以我不确定要更改什么。

Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "views.py" in showDocProfile
69. return render(request,'meddy1/docprofile.html',{'doctor': profile}, {'timeList': WaitingTime.objects.all()})
File "/Library/Python/2.7/site-packages/django/shortcuts/__init__.py" in render
53. return HttpResponse(loader.render_to_string(*args, **kwargs),

Exception Type: TypeError at /docprofile/1/
Exception Value: render_to_string() got multiple values for keyword argument 'context_instance'

这是我试图保存所有等待时间对象的 view.py

def showDocProfile(request, id):
profile = Doctor.objects.get(id=id)
return render(request,'meddy1/docprofile.html',{'doctor': profile}, {'timeList': WaitingTime.objects.all()})

这是我试图显示等待时间的模板 docprofile.html

{% for t in timeList %}
<h4>{t.time}</h4>
{% endfor %}

模型.py

class WaitingTime(models.Model):
time_choices = ( (10, 'Less than 10 Minutes'), (20, 'Less than 20 Minutes'), (30, 'Less than 30 Minutes'))
time = models.IntegerField(choices = time_choices, blank = True )
doctor = models.ForeignKey(Doctor)
doctor_seeker = models.ForeignKey(DoctorSeeker)
date = models.DateField()

class Doctor(models.Model):
avg_times = models.ManyToManyField(DoctorSeeker, through="WaitingTime")
name = models.CharField(max_length=30)
specialization = models.ForeignKey(Specialization)
clinic = models.ForeignKey(Clinic)
language = models.ManyToManyField(Language)
education1 = models.CharField(max_length=100)
education2 = models.CharField(max_length=100, null = True)
gender_choices = ( ('M', 'Male'), ('F','Female'),)
gender = models.CharField(max_length=5, choices = gender_choices, null=True)
profile_pic = models.ImageField(upload_to='/uploads/', null=True)
statement = models.TextField(null=True)
affiliation = models.CharField(max_length=100, null = True)

最佳答案

在调用 render() 时,您传递了 2 个字典,而您需要传递 1 个包含两个项目的字典,这被视为模板的上下文。

将你的全部更新为

return render(request,'meddy1/docprofile.html',
{'doctor': profile,
'timeList': WaitingTime.objects.all()
})

关于python - Django 1.6 TypeError render_to_string() 得到关键字参数 'context_instance' 的多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24157747/

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