2017-03-16 7 views
1

セキレイブログサイトを使用して - 私は、ブログサイトを作成セキレイを使用して、と私は暗礁にして実行してきましたよモデルフォームの問題

コメント。私は私のページにコメントモデルを追加しました。私は管理セクションを通してコメントを追加することができ、それらは正しい投稿に表示されますが、私が作成したコメントフォームは何らかの理由で表示されません。ここに関連コードがあります。私がどこに間違っていたかについてのヒントは非常に高く評価されます。カスタムDjangoのフォームが表示されない - セキレイ

ブログ/ models.py

class BlogPage(Page): 
    date = models.DateField("Post date") 
    intro = models.CharField(max_length=250) 
    body = RichTextField(blank=True) 
    #tag manager 
    tags = ClusterTaggableManager(through=BlogPageTag, blank=True) 

    #get feature image 
    def main_image(self): 
     gallery_item = self.gallery_images.first() 
     if gallery_item: 
      return gallery_item.image 
     else: 
      return None 

    search_fields = Page.search_fields + [ 
     index.SearchField('intro'), 
     index.SearchField('body'), 
    ] 

    content_panels = Page.content_panels + [ 
     MultiFieldPanel([ 
      FieldPanel('date'), 
      FieldPanel('tags'), 
     ], heading="Blog information"), 
     FieldPanel('intro'), 
     FieldPanel('body'), 
     InlinePanel('gallery_images', label="Gallery images"), 
    ] 

    def serve(self, request): 
     # Get current page 
     post = self 

     # Get comment form 
     form = CommentForm(request.POST or None) 

     # Check for valid form 
     if form.is_valid(): 
      comment = form.save(commit=False) 
      comment.post = post 
      comment.save() 
      return redirect(request.path) 
     return render_to_response(self, 
       { 
             'post': post, 
             'form': form, 
            }, 
            context_instance=RequestContext(request)) 

class Comment(models.Model): 
    post = models.ForeignKey(BlogPage, related_name='comments') 
    author = models.CharField(max_length=250) 
    text = models.TextField() 
    created_date = models.DateTimeField(default=timezone.now) 
    approved_comment = models.BooleanField(default=False) 

    def approve(self): 
     self.approved_comment = True 
     self.save() 

    def __unicode__(self): 
     return self.text 

    def __str__(self): 
     return self.text 

class CommentForm(forms.ModelForm): 

    class Meta: 
     model = Comment 
     fields = ('author', 'text',) 

blog_page.html

{% extends "base.html" %} 

{% load wagtailcore_tags wagtailimages_tags %} 

{% block body_class %}template-blogpage{% endblock %} 

{% block content %} 
    <div class="section"> 
     <div class="container"> 
      <h1 class="title">{{ page.title }}</h1> 
      <p class="meta subtitle">{{ page.date }}</p> 

       {% with page.main_image as main_image %} 
       {% if main_image %}{% image main_image fill-500x300 %}{% endif %} 
       {% endwith %} 
       <p>{{ main_image.caption }}</p> 

      <div class="hero-body subtitle">{{ page.intro }}</div> 
      <div class="content"> 

       {{ page.body|richtext }} 

       {% if page.tags.all.count %} 
        <div class="tags"> 
         <h3>Tags</h3> 
         {% for tag in page.tags.all %} 
          <span class="tag is-primary is-medium is-link"><a style="color: white" href="{% slugurl 'tags' %}?tag={{ tag }}">{{ tag }}</a></span> 
         {% endfor %} 
        </div> 
       {% endif %} 
       <p><a href="{{ page.get_parent.url }}">Return to blog archive</a></p> 
       <hr> 
       <br> 

       <form action="" method="POST"> 
        {% csrf_token %} 
        <table> 
         {{ form.as_table }} 
        </table> 
        <input class="control button is-primary" type='submit' name='submit' value='Add Comment'> 
       </form> 
       <br> 



      <hr> 
      <div class="section"> 
       {% if page.comments.all.count %} 
       <h2 class='subtitle'>Comments</h2> 

        <div class="comments"> 
        {% for comment in page.comments.all %} 


          {% if comment.approved_comment %} 
          <div class="comment"> 
           <h5 class="date">{{ comment.created_date }}</h5> 
           <strong><h3 class="title is-3">{{ comment.author }}</h3></strong> 
           <h4 class="subtitle is-5">{{ comment.text|linebreaks }}</h4> 
           <br> 
           <hr> 
          </div> 
          {% endif %} 

         {% empty %} 
          <br> 
          <p>No comments yet...</p> 
        {% endfor %} 
        </div> 
       {% endif %} 
      </div> 
     </div> 
     </div> 
    </div> 
{% endblock %} 

今、私はというエラーを取得しています:

File "/home/kenneth/development/web/sites/mysite/dynamicsalesops/blog/models.py", line 88, in serve 
context_instance=RequestContext(request)) 
TypeError: render_to_response() got an unexpected keyword argument 'context_instance' 

答えて

1

あなたview_post機能が使用されることはありません。 Wagtailでは、HTMLとしてのページのレンダリングは、別のビュー関数ではなく、ページモデル自体のserveメソッドで処理されます。http://docs.wagtail.io/en/v1.9/reference/pages/theory.html#anatomy-of-a-wagtail-request

+0

ありがとうございました。私はserveメソッドのドキュメントを見て、いくつかのアプローチを試みました。しかし、私はブログページに自分のコメントを表示する方法を理解するのに苦労しています。この問題に関するWagtailのレシピは、私がやろうとしていることには関係していないようです。任意の提案や例? –

関連する問題