加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

django 获取django template中获取当前url

发布时间:2020-12-15 17:14:24 所属栏目:大数据 来源:网络整理
导读:在实际开发中,经常需要在template中获取当前url。获取方法如下: django 1.9版本以上 ##?template文件中{{?request.path?}}??#??????????不带request.get参数?{{?request.get_full_path?}}??#?带request.get参数 django 1.9之前的版本 ##?settings.pyfrom?d

在实际开发中,经常需要在template中获取当前url。获取方法如下:

django 1.9版本以上

##?template文件中
{{?request.path?}}??#??????????不带request.get参数?
{{?request.get_full_path?}}??#?带request.get参数

django 1.9之前的版本

##?settings.py
from?django.conf.global_settings?import?TEMPLATE_CONTEXT_PROCESSORS?as?TCP

TEMPLATE_CONTEXT_PROCESSORS?=?TCP?+?(
????'django.core.context_processors.request',)

##?views.py
from?django.shortcuts?import?render_to_response
from?django.template?import?RequestContext

def?index(request):
????return?render_to_response(
????????'user/profile.html',????????{?'title':?'User?profile'?},????????context_instance=RequestContext(request)
????)


##?template
{{?request.path?}}


(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读