锚标记将字段值附加到当前 url 而不是仅仅导航到字段值 [英] Anchor tag appending field value to current url instead of just navigating to field value
问题描述
我有一个带有 website_link
字段的模型.
class Partner(models.Model):website_link = models.CharField(max_length=120)
我像这样在模板中访问它
{% if instance.logo %}<!-- 出于某种原因,网站链接只是附加到当前 url 的末尾--><a href="{{ instance.website_link }}"><img src='{{ instance.logo.url }}' class='img-responsive' alt=""></a>{% 万一 %}
当我在锚标签内的模板中调用它时,链接导航到当前网址,并将 website_link 附加到末尾.
所以如果 instance.website_url = www.partnerone.com
而不是去 www.partnerone.com
它去 http://127.0.0.1:8000/partners/partner-one/www.partnerone.com
听起来有些链接存储在您的 website_link
中是相对 url.如果它们不以 //
或 http://
或等价物开头,您将得到您所看到的结果.
I have a model with a field website_link
.
class Partner(models.Model):
website_link = models.CharField(max_length=120)
And I access it in the template like so
<div class="col-sm-3 col-sm-offset-1">
{% if instance.logo %}</a>
<!-- website link just gets appended to the end of current url for some reason-->
<a href="{{ instance.website_link }}"><img src='{{ instance.logo.url }}' class='img-responsive' alt=""></a>
{% endif %}
</div>
When I call this in the template inside of an anchor tag the link navigates to the current url with the website_link appended to the end.
So if instance.website_url = www.partnerone.com
instead of going to www.partnerone.com
it goes to http://127.0.0.1:8000/partners/partner-one/www.partnerone.com
It sounds like some links stored in your website_link
are relative urls. If they don't start with //
or http://
or equivalent, you will get the result you're seeing.
这篇关于锚标记将字段值附加到当前 url 而不是仅仅导航到字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!