how to get current url in django views
To get the current URL in Django views, you can use the request.build_absolute_uri() method.
For example:
from django.shortcuts import render
def my_view(request):
current_url = request.build_absolute_uri()
# Do something with the current URL
return render(request, 'my_template.html', context={'current_url': current_url})
In the above code, the request.build_absolute_uri() method returns the full absolute URL, including the scheme (e.g. "http" or "https"), hostname, and path. This can be useful if you need to dynamically generate links or perform other operations based on the current URL.
原文地址: https://www.cveoy.top/t/topic/8VR 著作权归作者所有。请勿转载和采集!