TypeError: coercing to Unicode: need string or buffer, WSGIRequest found
TypeError: coercing to Unicode: need string or buffer, WSGIRequest found
类型错误 /nvbn/home。html
强制转换为 Unicode:需要字符串或缓冲区,找到 WSGIRequest
请求方式:GET
请求 URL:http://127.0.0.1:8080/nvbn/home.html
Django 版本:1.7.2
异常类型:TypeError
异常值:
强制转换为 Unicode:需要字符串或缓冲区,找到 WSGIRequest
异常位置:C:\Anaconda\lib\site-packages\django\template\loaders\eggs.py in load_template_source, line 26
Python 可执行文件:C:\Anaconda\python.exe
Python版本:2.7.8
Python路径:
['c:\DjangoProjects\quickclaim',
'C:\Anaconda\lib\site-packages\setuptools-11.3.1-py2.7.egg',
'C:\Anaconda\lib\site-packages\django_ajax_search-1.5.1-py2.7.egg',
'C:\Anaconda\python27.zip',
'C:\Anaconda\DLLs',
'C:\Anaconda\lib',
'C:\Anaconda\lib\plat-win',
'C:\Anaconda\lib\lib-tk',
'C:\Anaconda',
'c:\anaconda\lib\site-packages\runipy-0.1.1-py2.7.egg',
'C:\Anaconda\lib\site-packages',
'C:\Anaconda\lib\site-packages\PIL',
'C:\Anaconda\lib\site-packages\Sphinx-1.2.3-py2.7.egg',
'C:\Anaconda\lib\site-packages\win32',
'C:\Anaconda\lib\site-packages\win32\lib',
'C:\Anaconda\lib\site-packages\Pythonwin']
服务器时间:2015年1月22日星期四15:07:25 -0500
这是我的模型:
class Claim(models.Model):
def __str__(self):
return self.claim_id
policy = models.ForeignKey(Policy);
claim_id = models.CharField(max_length=50, unique=True, db_index=True);
loss_dt = models.DateTimeField();
loss_location = models.CharField(max_length=100);
clam_stat = models.CharField(max_length=2, default='open');
cas_aia_cds_1_2 = models.CharField(max_length=50);
cas_aia_cds_3_4 = models.CharField(max_length=50);
reported_dt = models.DateTimeField();
loss_desc = models.TextField();
class Meta:
ordering = ['-loss_dt','reported_dt']
在views.py中:
def home(request):
try:
claims = m.Claim.objects.all()
claims_list = []
for c in claims:
claims_list.append(c.loss_desc)
context = RequestContext(request, {
'claim_list': claims_list
})
return render_to_response(request, 'home.html', context_instance=context)
except m.Claim.DoesNotExist:
raise Http404
我想做的是将声明对象列表发送到模板。
任何想法将不胜感激。
render_to_response
不接受 request
作为参数。
将其删除,其余保持原样。
类型错误 /nvbn/home。html
强制转换为 Unicode:需要字符串或缓冲区,找到 WSGIRequest
请求方式:GET
请求 URL:http://127.0.0.1:8080/nvbn/home.html
Django 版本:1.7.2
异常类型:TypeError
异常值:
强制转换为 Unicode:需要字符串或缓冲区,找到 WSGIRequest
异常位置:C:\Anaconda\lib\site-packages\django\template\loaders\eggs.py in load_template_source, line 26
Python 可执行文件:C:\Anaconda\python.exe
Python版本:2.7.8
Python路径:
['c:\DjangoProjects\quickclaim',
'C:\Anaconda\lib\site-packages\setuptools-11.3.1-py2.7.egg',
'C:\Anaconda\lib\site-packages\django_ajax_search-1.5.1-py2.7.egg',
'C:\Anaconda\python27.zip',
'C:\Anaconda\DLLs',
'C:\Anaconda\lib',
'C:\Anaconda\lib\plat-win',
'C:\Anaconda\lib\lib-tk',
'C:\Anaconda',
'c:\anaconda\lib\site-packages\runipy-0.1.1-py2.7.egg',
'C:\Anaconda\lib\site-packages',
'C:\Anaconda\lib\site-packages\PIL',
'C:\Anaconda\lib\site-packages\Sphinx-1.2.3-py2.7.egg',
'C:\Anaconda\lib\site-packages\win32',
'C:\Anaconda\lib\site-packages\win32\lib',
'C:\Anaconda\lib\site-packages\Pythonwin']
服务器时间:2015年1月22日星期四15:07:25 -0500
这是我的模型:
class Claim(models.Model):
def __str__(self):
return self.claim_id
policy = models.ForeignKey(Policy);
claim_id = models.CharField(max_length=50, unique=True, db_index=True);
loss_dt = models.DateTimeField();
loss_location = models.CharField(max_length=100);
clam_stat = models.CharField(max_length=2, default='open');
cas_aia_cds_1_2 = models.CharField(max_length=50);
cas_aia_cds_3_4 = models.CharField(max_length=50);
reported_dt = models.DateTimeField();
loss_desc = models.TextField();
class Meta:
ordering = ['-loss_dt','reported_dt']
在views.py中:
def home(request):
try:
claims = m.Claim.objects.all()
claims_list = []
for c in claims:
claims_list.append(c.loss_desc)
context = RequestContext(request, {
'claim_list': claims_list
})
return render_to_response(request, 'home.html', context_instance=context)
except m.Claim.DoesNotExist:
raise Http404
我想做的是将声明对象列表发送到模板。
任何想法将不胜感激。
render_to_response
不接受 request
作为参数。
将其删除,其余保持原样。