2024-05-23 23:01:18 发布
网友
我知道还有一个题目和我的题目差不多,但那个题目的答案对我不起作用。我的网址是这样的:
http://domain.com/videos/dvd/1/
如果我使用{{baseurl}}或{{ request.get_full_path }},我只得到这个部分:
{{baseurl}}
{{ request.get_full_path }}
http://domain.com/videos/
如何获取整个url?我需要能够从模板一级做到这一点。
p.S.它应该忽略url中的任何参数。
您可以在视图中获取它并将其传递到模板上下文中,以便在那里可以使用它。
https://docs.djangoproject.com/en/1.3/ref/request-response/#django.http.HttpRequest.build_absolute_uri
full_url = request.build_absolute_uri(None) # pass full_url into the template context.
您可以在视图中获取它并将其传递到模板上下文中,以便在那里可以使用它。
https://docs.djangoproject.com/en/1.3/ref/request-response/#django.http.HttpRequest.build_absolute_uri
相关问题 更多 >
编程相关推荐