Python django-获取用于调用django视图(包括参数)的确切Get url
我有一个接受GET参数的视图(可通过Python django-获取用于调用django视图(包括参数)的确切Get url,python,django,Python,Django,我有一个接受GET参数的视图(可通过请求.GET访问,并且这些参数存在于uri中) 在视图中,我想获得用于调用该视图的确切uri 例如: 如果呼叫http://best.site.ever/?this=that&that=this我希望能够在视图中获取它 def best_view_ever(request): calling_uri = get_calling_uri(request) calling_uri # this should be http://best.site.
请求.GET访问,并且这些参数存在于uri中)
在视图中,我想获得用于调用该视图的确切uri
例如:
如果呼叫http://best.site.ever/?this=that&that=this
我希望能够在视图中获取它
def best_view_ever(request):
calling_uri = get_calling_uri(request)
calling_uri # this should be http://best.site.ever/?this=that&that=this
这可以通过任何方式实现吗?Django请求对象有一个可用的助手方法,称为:
build\u absolute\u uri
请求对象的方法在这里会很有用
def get_calling_uri(request):
return request.build_absolute_uri()
def best_view_ever(request):
calling_uri = get_calling_uri(request)
print calling_uri # this should be http://best.site.ever/?this=that&that=this
def get_calling_uri(request):
return request.build_absolute_uri()
def best_view_ever(request):
calling_uri = get_calling_uri(request)
print calling_uri # this should be http://best.site.ever/?this=that&that=this