本文介绍了如何获取Django模板中的当前URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何获取模板中的当前网址。
I was wondering how to get the current URL within a template.
说我的网址是
/user/profile/
模板?
推荐答案
## settings.py
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request',
)
## views.py
from django.template import *
def home(request):
return render_to_response('home.html', {}, context_instance=RequestContext(request))
## template
{{ request.path }}
这篇关于如何获取Django模板中的当前URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!