我怎么能得到完整/绝对的URL(例如https://example.com/some/path)在Django没有网站模块?这太愚蠢了……我不需要查询我的数据库来抓取URL!
我想使用reverse()。
我怎么能得到完整/绝对的URL(例如https://example.com/some/path)在Django没有网站模块?这太愚蠢了……我不需要查询我的数据库来抓取URL!
我想使用reverse()。
当前回答
这在我的模板中很管用:
{{ request.scheme }}://{{ request.META.HTTP_HOST }}{% url 'equipos:marca_filter' %}
我需要完整的url传递给一个js获取函数。 我希望这对你有帮助。
其他回答
你可以试试"request.get_full_path()"
检查请求。META字典。我认为它有服务器名和服务器端口。
<div class='col-12 col-md-6'>
<p class='lead'>Login</p>
{% include 'accounts/snippets/form.html' with form=login_form next_url=request.build_absolute_uri %}
</div>
例如,在这里,我说加载表单,并告诉表单,下一个URL是当前的URL,这段代码呈现
这在我的模板中很管用:
{{ request.scheme }}://{{ request.META.HTTP_HOST }}{% url 'equipos:marca_filter' %}
我需要完整的url传递给一个js获取函数。 我希望这对你有帮助。
如果你想使用reverse(),你可以这样做:request。build_absolute_uri(反向(view_name, args = (obj。pk,)))