python - Unable to get the comment form in django using django comments framework -
i trying integrate django comment app own app named 'blog'. however, when trying comment form, ma getting 'none' instead of model form.
below "home.html" template code want form appear.
{% load staticfiles %} {%load comments%} <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content=""> <meta name="author" content=""> <title>sourav's blog</title> <!-- bootstrap core css --> {%block styling%} <link href="{%static 'css/bootstrap.min.css'%}" rel="stylesheet"> <!-- custom css --> <link href="{%static 'css/blog-post.css'%}" rel="stylesheet"> {%endblock styling%} <!-- html5 shim , respond.js ie8 support of html5 elements , media queries --> <!-- warning: respond.js doesn't work if view page via file:// --> <!--[if lt ie 9]> <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> <![endif]--> </head> <body> <!-- navigation --> <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation"> <div class="container"> <!-- brand , toggle grouped better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">ideate</a> </div> <!-- collect nav links, forms, , other content toggling --> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <ul class="nav navbar-nav"> <li> <a href="{%url 'blog_new_post'%}">new idea</a> </li> <!-- <li><a href="{%url 'blog_login'%}">login</a></li> --> {{user.is_authenticated}} {% if user.is_authenticated %} <li> <a href="{%url 'blog_logout'%}">logout</a> </li> {% else %} <li> <a href="{%url 'blog_login'%}">login</a> </li> {% endif %} <li> <a href="#">help</a> </li> {% if user.is_authenticated %} <li> <a href="#">hi {{user.username}}</a> </li> {%else%} {% endif %} </ul> </div> <!-- /.navbar-collapse --> </div> <!-- /.container --> </nav> <!-- page content --> <div class="container"> <div class="row"> <!-- blog post content column --> <div class="col-lg-8"> <!-- blog post --> <!-- title --> <h1>idea blog</h1> <!-- author --> <p class="lead"> <a href="#">ideate</a> </p> <hr> <!-- date/time --> <p><span class="glyphicon glyphicon-time"></span> posted on <!-- {%for in blog_data%} {{i.posted_on}} {%endfor%}</p> --> {% in last_element %} {{i.posted_on}} {%empty%} <span>no data</span> {%endfor%} <hr> <!-- preview image --> <img class="img-responsive" src="http://placehold.it/900x300" alt=""> <hr> <!-- post content --> <!-- <p>below result</p> --> <!-- <p>{{blog_data}}</p> --> <p> <!-- {%for in blog_data%} <h1>{{i.title}}</h1> <p>{{i.description}}</p> {%empty%} <span>no data</span> {%endfor%} --> <!-- {{last_element}} --> {% in last_element %} <h1>{{i.title}}</h1> <p>{{i.description}}</p> {%empty%} <span>no data</span> {%endfor%} {% get_comment_count blog.blogpost 2 comment_count %} <p>{{ comment_count }} comments have been posted.</p> {% get_comment_list blog.blogpost 1 comment_list %} {% comment in comment_list %} <p>posted by: {{ comment.user_name }} on {{ comment.submit_date }}</p> <p>comment: {{ comment.comment }}</p> {% endfor %} {%get_comment_form blog.blogpost comment_form %} <p>{{comment_form}}</p> {% get_comment_form blog.blogpost form %} <!-- context variable called form created necessary hidden fields, timestamps , security hashes --> <table> <form action="{% comment_form_target %}" method="post"> {% csrf_token %} {{ form }} <tr> <td colspan="2"> <input type="submit" name="submit" value="post"> <input type="submit" name="preview" value="preview"> </td> </tr> </form> </table> </p> <hr> <!-- blog comments --> <!-- comments form --> <div class="well"> <h4>leave comment:</h4> <form role="form"> <div class="form-group"> <textarea class="form-control" rows="3"></textarea> </div> <button type="submit" class="btn btn-primary">submit</button> </form> </div> <hr> <!-- posted comments --> <!-- comment --> <div class="media"> <a class="pull-left" href="#"> <img class="media-object" src="http://placehold.it/64x64" alt=""> </a> <div class="media-body"> <h4 class="media-heading">start bootstrap <small>august 25, 2014 @ 9:30 pm</small> </h4> cras sit amet nibh libero, in gravida nulla. nulla vel metus scelerisque ante sollicitudin commodo. cras purus odio, vestibulum in vulputate at, tempus viverra turpis. fusce condimentum nunc ac nisi vulputate fringilla. donec lacinia congue felis in faucibus. </div> </div> <!-- comment --> <div class="media"> <a class="pull-left" href="#"> <img class="media-object" src="http://placehold.it/64x64" alt=""> </a> <div class="media-body"> <h4 class="media-heading">start bootstrap <small>august 25, 2014 @ 9:30 pm</small> </h4> cras sit amet nibh libero, in gravida nulla. nulla vel metus scelerisque ante sollicitudin commodo. cras purus odio, vestibulum in vulputate at, tempus viverra turpis. fusce condimentum nunc ac nisi vulputate fringilla. donec lacinia congue felis in faucibus. <!-- nested comment --> <div class="media"> <a class="pull-left" href="#"> <img class="media-object" src="http://placehold.it/64x64" alt=""> </a> <div class="media-body"> <h4 class="media-heading">nested start bootstrap <small>august 25, 2014 @ 9:30 pm</small> </h4> cras sit amet nibh libero, in gravida nulla. nulla vel metus scelerisque ante sollicitudin commodo. cras purus odio, vestibulum in vulputate at, tempus viverra turpis. fusce condimentum nunc ac nisi vulputate fringilla. donec lacinia congue felis in faucibus. </div> </div> <!-- end nested comment --> </div> </div> </div> <!-- blog sidebar widgets column --> <div class="col-md-4"> <!-- blog search --> <div class="well"> <h4>blog search</h4> <div class="input-group"> <input type="text" class="form-control"> <span class="input-group-btn"> <button class="btn btn-default" type="button"> <span class="glyphicon glyphicon-search"></span> </button> </span> </div> <!-- /.input-group --> </div> <!-- blog categories --> <div class="well"> <h4>blog categories</h4> <div class="row"> <div class="col-lg-6"> <ul class="list-unstyled"> <li><a href="#">category name</a> </li> <li><a href="#">category name</a> </li> <li><a href="#">category name</a> </li> <li><a href="#">category name</a> </li> </ul> </div> <div class="col-lg-6"> <ul class="list-unstyled"> <li><a href="#">category name</a> </li> <li><a href="#">category name</a> </li> <li><a href="#">category name</a> </li> <li><a href="#">category name</a> </li> </ul> </div> </div> <!-- /.row --> </div> <!-- side widget --> <div class="well"> <h4>side widget well</h4> <p>lorem ipsum dolor sit amet, consectetur adipisicing elit. inventore, perspiciatis adipisci accusamus laudantium odit aliquam repellat tempore quos aspernatur vero.</p> </div> </div> </div> <!-- /.row --> <hr> <!-- footer --> <footer> <div class="row"> <div class="col-lg-12"> <p>copyright © website 2014</p> </div> </div> <!-- /.row --> </footer> </div> <!-- /.container --> <!-- jquery --> {%block javascript%} <script src="{%static 'js/jquery.js'%}"></script> <!-- bootstrap core javascript --> <script src="{%static 'js/bootstrap.min.js'%}"></script> {%endblock javascript%} </body> </html>
below code views.py called when hit homepage "home.html"
def home(request): blog_data = blogpost.objects.all() last_element = blogpost.objects.filter(id = len(blog_data)) context = {'blog_data':blog_data, "last_element":last_element} #last_element = list(blogpost.objects.all().reverse()[0]) print("last_element",last_element, "blog_data",blog_data,"context",context) return render(request, 'blog/home.html', context)
models.py
from django.db import models django.contrib.auth.models import user # create models here. class blogpost(models.model): title = models.charfield(max_length = 30) posted_by = models.charfield(max_length = 30) posted_on = models.datetimefield(auto_now_add = true) description = models.charfield(max_length = 200) comment = models.charfield(max_length = 150) tags = models.charfield(max_length=50, default = "notag") def __str__(self): #return "{0} : {1}".format(self.title, self.description) return self.title
please me out of this. please let me know if other information required on same.
looking @ the documentation get_comment_form
, looks have include blogpost
's id when use tag:
{% get_comment_form blog.blogpost last_element.id comment_form %}
Comments
Post a Comment