why request.path return None?

   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.



原文地址:https://www.cnblogs.com/slider/p/2980992.html