slider

还是菜鸟
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

why request.path return None?

Posted on 2013-03-25 16:26  slider  阅读(269)  评论(0编辑  收藏  举报

   in django, sometimes you want to pass value of current page path , you will do this follows:

  a. <form action="./?next={{request.path}}" method="post">...</form>

  b.<form action="" method="post">

   <input type="hidden" name="next" value="{{request.path}}"/>

   </form>

  c.<a href="xxx/?next={{request.path}}">xx</a>

  however, perheps you find out that the value of 'next' is None in views.py. so you could think that request is None. But my code is that:

def index(request):
    xxxx
    return render_to_response('index.html',{},RequestContext(request))

  through my test. if you should apparently pass request, it will work ok. now the modified code is as follow:

def index(request):
    xxxx
    return render_to_response('index.html',{'request':request},RequestContext(request))

  and i don't know why. if anyone konws,pleasure tell me the answer.