djangoモデルからデータを取得し、forループを使用してテンプレートにデータを表示していますが、次のようになっています。TypeError at /jobs/
__init__() takes exactly 1 argument (8 given)
これは、データをフェッチするための私のビューコードです。
jobs_cities=City.objects.filter(job__isnull=False).distinct().annotate(jobs_count=models.Count('job')).order_by('jobs_count')[:6]
次に、ビューファイルの次の行を使用してこのデータをテンプレートに渡します。
return render_to_response('jobs/list.html', locals(),context_instance=RequestContext(request))
次に、テンプレートに次のように表示します。
{% for job_city in jobs_cities %}
<li><a href="#">Jobs in {{job_city.name}} </a></li>
{% endfor %}
スタックトレース:
Environment:
Request Method: GET
Request URL: http://localhost:8000/jobs/
Django Version: 1.4.1
Python Version: 2.6.5
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'jobs')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Template error:
In template /media/../templates/jobs/list.html, error at line 93
__init__() takes exactly 1 argument (8 given)
83 : <div class="clear"></div>
84 :
85 : </div><!--float_left-->
86 :
87 : <div class="float_right">
88 : <div class="post_btn"><a href="#"><img src="{{STATIC_URL}}images/post_btn.gif" border="none" alt=""><br><img src="{{STATIC_URL}}images/ffree_text.gif"></a></div><!--post_btn-->
89 : <div class="create_prfoile_btn"><a href="#"><img src="{{STATIC_URL}}images/banner.gif" alt="" border="none"></a></div><!---create_prfoile_btn-->
90 : <div class="clear"></div>
91 : <div class="featured_jobs">
92 : <ul>
93 : {% for job_city in jobs_cities %}
94 : <li><a href="#">Jobs in {{job_city.name}} </a></li>
95 : {% endfor %}
96 : </ul>
97 :
98 : </div><!--featured_jobs-->
99 :
100 : </div><!--float_right-->
101 :
102 :
103 : <div class="clear"></div>
Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/media/Local Disk/programming/django_projects/kaasib/jobs/views.py" in list
38. return render_to_response('jobs/list.html', locals(),context_instance=RequestContext(request))
File "/usr/local/lib/python2.6/dist-packages/django/shortcuts/__init__.py" in render_to_response
20. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py" in render_to_string
176. return t.render(context_instance)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
140. return self._render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
823. bit = self.render_node(node, context)
File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py" in render
123. return compiled_parent._render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
823. bit = self.render_node(node, context)
File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py" in render
62. result = block.nodelist.render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
823. bit = self.render_node(node, context)
File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/defaulttags.py" in render
145. len_values = len(values)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py" in __len__
85. self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py" in iterator
301. obj = model(*row[index_start:aggregate_start])
Exception Type: TypeError at /jobs/
Exception Value: __init__() takes exactly 1 argument (8 given)
デバッグコードも調べたところ、jobs_citiesが空のリストであることが示されているので、実際に何が間違っているのか知りたいですか?
よろしくお願いします。