用户输入的链接在Django中显示为文本
我刚刚在用Django(python版本2.7.8,Django verion 1.6)构建的社交网络应用程序上完成了用户评论系统的创建 评论系统一切正常,但我遇到了一个问题。如果用户在其评论中提交指向外部站点的链接,该链接将显示为纯文本。我想用户提交的链接自动被视为一个链接,其他用户可以点击 有人知道这个问题的潜在解决方案吗 models.py用户输入的链接在Django中显示为文本,django,django-forms,django-templates,django-1.6,django-comments,Django,Django Forms,Django Templates,Django 1.6,Django Comments,我刚刚在用Django(python版本2.7.8,Django verion 1.6)构建的社交网络应用程序上完成了用户评论系统的创建 评论系统一切正常,但我遇到了一个问题。如果用户在其评论中提交指向外部站点的链接,该链接将显示为纯文本。我想用户提交的链接自动被视为一个链接,其他用户可以点击 有人知道这个问题的潜在解决方案吗 models.py class Comment(models.Model): #Model that defines the Commenting system
class Comment(models.Model):
#Model that defines the Commenting system
created = models.DateTimeField(editable =False)
author = models.CharField(max_length = 200, editable = False)
body = models.TextField()
item = models.ForeignKey(BucketListItem)
def __unicode__(self):
return self.body
comment-template.html
<h2>Comments:</h2>
<br>
{% if comments %}
{% for comment in comments %}
<div class = "comment-div">
<h5>{% avatar comment.author 40 %}</h5>
<h5><a href = "/bucketlist/userstats/{{comment.author}}/"> {{comment.author}}</a></h5>
<h5 class ="timesince">{{ comment.created|timesince}} ago.</h3>
<br>
<br>
<p>{{comment.body}}</p>
{% if comment.author == current_user %}
<a href="/bucketlist/item/{{comment.id}}/delete-comment/"><span class = "fa fa-close"></span></a>
{% endif %}
</div>
{% endfor %}
<br>
<hr>
<br>
{% else %}
<p>There are no comments yet. Be the first to add one!</p>
{% endif %}
<h5 class = "leave-comment">Leave a Comment Here: </h5>
<br>
<form action="/bucketlist/item/{{id}}/" method = "post" role = "form">
<div class = "form-group">
{% csrf_token %}
{% for field in form %}
{{ field.errors }}
{{ field }}
<br>
{% endfor %}
<br>
<input type = "submit" value = "Submit" class="btn btn-warning">
</div>
<br>
注释:
{%if注释%}
{注释%中的注释为%}
{%avatar comment.author 40%}
{{comment.created | timesince}}年前。
{{comment.body}
{%if comment.author==当前用户%}
{%endif%}
{%endfor%}
{%else%}
目前还没有评论。第一个添加一个
{%endif%}
请在此处留言:
{%csrf_令牌%}
{%形式的字段为%}
{{field.errors}}
{{field}}
{%endfor%}
您应该能够使用Django提供的工具来实现这一点
<p>{{ comment.body | urlize }}</p>
{{comment.body | urlize}
这会将注释正文中的任何链接转换为实际的
标记。您应该能够使用Django提供的标记来完成此操作
<p>{{ comment.body | urlize }}</p>
{{comment.body | urlize}
这会将注释正文中的任何链接转换为实际的
标记。您能否显示注释后面的相关模型以及负责显示注释的模板代码?谢谢。好了,如果可能的话,我不想使用所见即所得文本编辑器。你能显示注释背后的相关模型和负责显示注释的模板代码吗?谢谢。好了,如果可能的话,我宁愿不使用所见即所得文本编辑器。这很好用,非常感谢凯文!这正是我要找的。非常好用,非常感谢凯文!这正是我要找的。