2016-04-14 10 views
0

私はDjangoをプロジェクトのWebフレームワークとして使用しています。 models.pyに保存されたデータをhtmlページに表示するのに問題があります。ちょっとした背景のために、Pythonのtextblobパッケージを使って感情分析を行っています。分析はanalyze.pyで実行され、Djangoが提供するcall_command(解析)を使用してviews.pyで呼び出されます。Django Python - models.pyからhtmlページのデータを表示しています...アンパックする値が多すぎます

以下

は、我々が持っているものです。

analysis.py

pt_terrible = SentimentPercentage(pt_terrible = (len(terrible_list)/len(activity_text_list))) 
pt_terrible.save() 

models.py

class SentimentPercentage(models.Model): 
    pt_terrible = models.FloatField(null=True, blank=True) 
    pt_bad = models.FloatField(null=True, blank=True) 
    pt_neutral = models.FloatField(null=True, blank=True) 
    pt_good = models.FloatField(null=True, blank=True) 
    pt_excellent = models.FloatField(null=True, blank=True) 

views.py

def results(request): 
    sentiment = call_command('analysis') 
    terrible_sentiment = SentimentPercentage.objects.get('**pt_terrible') 
    context = {'sentiment': sentiment, 'terrible_sentiment': terrible_sentiment} 
    return render(request, 'sawa/results.html', context) 

results.html

<section> 
      <form> 
       <fieldset> 

        <!-- RESULTS WILL BE POSTED HERE --> 

        <p>{{terrible_sentiment.pt_terrible}}</p> 

        <p>RESULTS WILL BE POSTED HERE</p> 
       </fieldset> 
      </form> 
     </section> 

私たちは、エラー「解凍するためにあまりにも多くの値(2を期待)」...以下トレースバックがある受信されています。私たちは物事の束を試してみました

Request Method: GET 
Request URL: http://localhost:8000/sawa/results/ 

Django Version: 1.9.5 
Python Version: 3.4.3 
Installed Applications: 
['sawa.apps.SawaConfig', 
'django.contrib.admin', 
'django.contrib.auth', 
'django.contrib.contenttypes', 
'django.contrib.sessions', 
'django.contrib.messages', 
'django.contrib.staticfiles'] 
Installed Middleware: 
['django.middleware.security.SecurityMiddleware', 
'django.contrib.sessions.middleware.SessionMiddleware', 
'django.middleware.common.CommonMiddleware', 
'django.middleware.csrf.CsrfViewMiddleware', 
'django.contrib.auth.middleware.AuthenticationMiddleware', 
'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 
'django.contrib.messages.middleware.MessageMiddleware', 
'django.middleware.clickjacking.XFrameOptionsMiddleware'] 



Traceback: 

File "C:\Python34\lib\site-packages\django\core\handlers\base.py" in get_response 149.response = self.process_exception_by_middleware(e, request) 

File "C:\Python34\lib\site-packages\django\core\handlers\base.py" in get_response 147.response = wrapped_callback(request, *callback_args, **callback_kwargs) 

File "C:\Users\...\Documents\Spring Semester 2016\ISA 406\Project\Django Project\isa406\sawa\views.py" in results 17.terrible_sentiment = SentimentPercentage.objects.get('**pt_terrible') 

File "C:\Python34\lib\site-packages\django\db\models\manager.py" in manager_method 122.return getattr(self.get_queryset(), name)(*args, **kwargs) 

File "C:\Python34\lib\site-packages\django\db\models\query.py" in get 378.clone = self.filter(*args, **kwargs) 

File "C:\Python34\lib\site-packages\django\db\models\query.py" in filter 790.return self._filter_or_exclude(False, *args, **kwargs) 

File "C:\Python34\lib\site-packages\django\db\models\query.py" in _filter_or_exclude 808.clone.query.add_q(Q(*args, **kwargs)) 

File "C:\Python34\lib\site-packages\django\db\models\sql\query.py" in add_q 1243.clause, _ = self._add_q(q_object, self.used_aliases) 

File "C:\Python34\lib\site-packages\django\db\models\sql\query.py" in _add_q 

環境をviews.pyを使用して、運が悪くないようにしてください。ご提案がありましたら、感謝いたします。

+1

完全なトラックバックを表示する必要があります。 –

答えて

2

あなたは簡単に問題を診断するために私達を可能にするトレースバックを提供していないが、このラインは疑わしい:

terrible_sentiment = SentimentPercentage.objects.get('**pt_terrible') 

引数は引用符であってはなりません。

+0

トレースバックが追加されました。 – Spidunk

+0

トレースバックで同じ行が強調表示されているので、私は正しいと思います。私の解決策を試しましたか? –

+0

はい、引用符を削除しようとしました。 "name 'pt_terrible'が定義されていません"というエラーが表示されます。 – Spidunk

関連する問題