【发布时间】:2021-08-02 07:56:44
【问题描述】:
我正在使用 django-comments-xtd 在 Wagtail 中设置 cmets,而我无法弄清楚的一件事是为什么我的评论永久链接一直转到 https://example.com/news/bloggy-test-post/#c1 而不是 https://localhost:8000/news/bloggy- test-post/#c1.
我在 Wagtail Google 小组中发现了一个有类似问题的用户,他发现他们在 Wagtail 管理员中将“example.com”设置为他们的网站。但是我的设置中只有一个站点,它当前设置为“localhost”,端口为 8000。
Screenshot of the Wagtail admin site showing there is one site set to localhost with a port of 8000
我在所有文件和库中搜索“example.com”,发现的唯一其他设置是 base.py 中的 BASE_URL 设置。我尝试将其更改为 http://localhost:8000 并且评论永久链接仍被定向到“example.com”。
我还缺少其他设置吗?或者我应该以其他方式获取 URL?
目前,我有这段代码用于在我的 models.py 文件中获取 url:
def get_absolute_url(self):
return self.get_url()
这是我模板中的 cmets 部分代码:
{% get_comment_count for page as comment_count %}
<p>
<a href="{% pageurl page %}#comments">
{{ comment_count }} comment{{ comment_count|pluralize }}
</a>
{{ comment_count|pluralize:"has,have" }} been posted.
</p>
{% render_xtdcomment_tree for page %}
{% render_comment_form for page %}
这是(希望)来自 django-cmets-xtd 的 comment_tree.html 的相关部分:
<h6 class="mb-1 small d-flex">
<div class="mr-auto">{{ item.comment.submit_date }} - {% if item.comment.url and not item.comment.is_removed %}<a href="{{ item.comment.url }}" target="_new">{% endif %}{{ item.comment.name }}{% if item.comment.url %}</a>{% endif %}{% if item.comment.user and item.comment.user|has_permission:"django_comments.can_moderate" %} <span class="badge badge-secondary">{% trans "moderator" %}</span>{% endif %} <a class="permalink" title="{% trans 'comment permalink' %}" href="{% get_comment_permalink item.comment %}">¶</a></div>
<span>
{% if not item.comment.is_removed %}
{% if perms.comments.can_moderate %}
{% if item.flagged_count %}
<span class="badge badge-danger" title="{% blocktrans count counter=item.flagged_count %}A user has flagged this comment as inappropriate.{% plural %}{{ counter }} users have flagged this comment as inappropriate.{% endblocktrans %}">{{ item.flagged_count }}</span>
{% endif %}
{% endif %}
{% if allow_flagging and item.flagged %}
<i class="fas fa-flag text-danger" title="{% trans 'comment flagged' %}"></i>
{% elif allow_flagging %}
<a class="mutedlink"
href="{% url 'comments-flag' item.comment.pk %}">
<i class="fas fa-flag" title="{% trans 'flag comment' %}"></i>
</a>
{% endif %}
{% if perms.comments.can_moderate %}
<a class="mutedlink"
href="{% url 'comments-delete' item.comment.pk %}"><i class="fas fa-trash-alt" title="{% trans 'remove comment' %}"></i></a>
{% endif %}
{% endif %}
</span>
</h6>
【问题讨论】:
-
作为后续,我在“站点”下添加了另一个站点,只是为了看看创建一个新站点是否能解决问题。当有两个站点“localhost”和“site.localhost”时,URL 表现良好并转到适当的站点。但是,如果我删除其中一个站点,它将恢复为使用“example.com”。所以我猜现在我需要调整或删除多站点设置。我不需要多站点。我认为它出现在默认的演示项目中......
标签: django comments wagtail django-comments