我从view.py文件传递上下文
def change_password(request,pk=None):
user = MyUser.objects.get(pk=pk)
if request.method == "POST":
form = PasswordChangeForm(user=user, data=request.POST)
if form.is_valid():
form.save()
update_session_auth_hash(request, form.user)
return render(request, "nurse/change_password.html", {"user_id":user.id}) // passing user_id as context
我可以在我的html文件中看到这个值
<div class="form-group">
<label class="control-label allign col-sm-3" > {{user_id}} Old Password </label> // user_id is giving the right value
</div>
但是当我尝试在行动中获取相同的内容而不是它不起作用时:
<form class="form-horizontal login-box2" action="{% url 'booking:change_password' user_id %}" role="form" method="post"> // not getting user_id here
<div class="form-group">
<label class="control-label allign col-sm-3" > {{user_id}} Old Password </label> // getting user_id here
</div>
<div class="form-group">
<li> <button type="submit" class="btn btn-primary f-w-b f-s-18">Change</button> </li>
</div>
</form>
谁能告诉我我做错了什么?
由于
EDITED
添加urls.py代码:
url(r'^change_password/(?P<pk>[0-9]+)/$',views.change_password,name='change_password'),