2017-12-14 12 views
-1

私はHTMLでレンダリングされていないコンテキストスケールをレンダリングしようとしており、エラーを表示することができます。私は検査/コンソールでもAtom端末でもエラーは出ません。コンテキストがdjango Appでレンダリングされない

0-100%(JavaScriptを使用)の縮尺で を使ってアンケートアプリを開発していますが、何らかの理由でレンダリングされません。ここ

は私のコードです: views.py

class SurveyDetail(View): 

    def get(self, request, *args, **kwargs): 
     survey = get_object_or_404(Survey, is_published=True, id=kwargs['id']) 
     if survey.template is not None and len(survey.template) > 4: 
      template_name = survey.template 
     else: 
      if survey.display_by_question: 
       template_name = 'survey/survey.html' 
      else: 
       template_name = 'survey/one_page_survey.html' 
     if survey.need_logged_user and not request.user.is_authenticated(): 
      return redirect('%s?next=%s' % (settings.LOGIN_URL, request.path)) 
     categories = Category.objects.filter(survey=survey).order_by('order') 
     form = ResponseForm(survey=survey, user=request.user, 
          step=kwargs.get('step', 0)) 
     #try: 
     get_scale = form.get_multiple_scale() 
     #except: 
     # get_scale = None 
     context = { 
      'response_form': form, 
      'survey': survey, 
      'categories': categories, 
      'scales': get_scale 
     } 

     return render(request, template_name, context) 

form.py:

class ResponseForm(models.ModelForm): 

    WIDGETS = { 
     Question.TEXT: forms.Textarea, 
     Question.SHORT_TEXT: forms.TextInput, 
     Question.RADIO: forms.RadioSelect, 
     Question.SELECT: forms.Select, 
     Question.SELECT_IMAGE: ImageSelectWidget, 
     Question.SELECT_MULTIPLE: forms.CheckboxSelectMultiple, 
     Question.SCALE: forms.TextInput, 
    } 

    class Meta(object): 
     model = Response 
     fields =() 

    def __init__(self, *args, **kwargs): 
     """ Expects a survey object to be passed in initially """ 
     self.survey = kwargs.pop('survey') 
     self.user = kwargs.pop('user') 
     try: 
      self.step = int(kwargs.pop('step')) 
     except KeyError: 
      self.step = None 
     super(ResponseForm, self).__init__(*args, **kwargs) 
     self.uuid = uuid.uuid4().hex 
     self.steps_count = len(self.survey.questions.all()) 
     # add a field for each survey question, corresponding to the question 
     # type as appropriate. 
     data = kwargs.get('data') 
     for i, question in enumerate(self.survey.questions.all()): 
      is_current_step = i != self.step and self.step is not None 
      if self.survey.display_by_question and is_current_step: 
       continue 
      else: 
       try: 
        self.scales = question.get_multiple_scales() 
       except: 
        self.scales = None 
       self.add_question(question, data) 

    def get_multiple_scale(self): 
     mscale = [] 
     for items in self.scales: 
      index, question = items 
      tag = "<p class='tagged'>{}</p>".format(question) 
      mscale.append(tag) 
     return mscale 

HTML:あなたはキャッチオールexcept句を持っている

{% load bootstrap %} 
{% load static %} 
{% load i18n %} 
{% load survey_extras %} 

<table class="table"> 
    <!--<thead> 
     <tr> 
     <th> Question </th> 
     <th> Answers </th> 
     </tr> 
    </thead> --> 
    <tbody> 
{% for form in response_form %} 
    {% if form.field.widget.attrs.category == category.name or not form.field.widget.attrs.category %} 
     <tr class="{% if form.errors%} danger {% endif %}"> 
      <td> 
       <div class="question-title"> 
       <h4>{{ form.label|safe }}</h4> 
       </div> 

       {% if form.field.required %} 
        <span class="glyphicon glyphicon-asterisk" style="color:red"> </span> 
       {% endif %} 
       <span class="help-inline" style="color:red"> 
        <strong> {% for error in form.errors %}{{ error }}{% endfor %} </strong> 
       </span> <br> 

       <div class="answers"> 
       {% for field in form %} 
         <ul> 
         {{ field }} 
         </ul> 
        {% endfor%} 
        {% if "hidden" in form.field.widget.attrs %} 
         <br> 
         {% for scale in scales %} 
          {{ scale|safe }} 
          <div id="rate" class="scale"> 
          </div> 
          <div class="scale-title"> 
          <div class="container"> 
           <div class="row"> 
           <div class="col scaleleft"> 
            0% 
           </div> 
           <div class="col scaleright"> 
            100% 
           </div> 

           </div> 

          </div> 

          </div> 
          <br> 
         {% endfor %} 
        {% endif %} 
       </div> 

      </td> 
     </tr> 
    {% endif %} 
{% endfor %} 
    </tbody> 
</table> 
+0

print(template_name)とコンソールで出力を確認するとファイルの問題が発生する可能性があります。追跡して修正する必要があります。 –

+0

出力はsurvey/survey.htmlであり、そのファイルには、私の投稿にhtmlが含まれている{%include "survey/question.html"%}があります – Ben2pop

+0

htmlとしてここに示したのと同じページですか? –

答えて

0

getメソッドで使用されます。それは非常に非常に悪い考えです。 get_multiple_scaleメソッドでエラーが発生した場合は、をキャッチしてを隠しています。おそらく、そこに何かが間違っているかもしれませんが、あなたのコードでは何を言うのが不可能になります。

try/exceptを削除します。

あなたのフォームのinitメソッドにも同様のものがあります。そこにはそれほど意味がなくなり、get_multiple_scalesで反復していることが非常にあるself.scalesにNoneを割り当てることになります。ここには非常に奇妙な円形の定義があります。

+0

こんにちはDaniel、 私はtry/exceptに削除されましたが、レンダリングしない – Ben2pop

関連する問題