1

views.py

def edit_report(request, report_id):

    user = request.user
    if 'report_id' in request.session:
        del request.session['report_id']
    try:
        member = Members.objects.get(member=user)
        account_user = member.user
    except:
        account_user = user.id
    request.session['report_id'] = report_id
    request.session['account_user'] = account_user
    request.session["edit_report"] = True  
    return redirect('method_name')

In my application on clicking a button,it takes to edit_report method and if the application is run through that method request.session["edit_report"] the session becomes True it is mentioned in views like this request.session["edit_report"] = True.I want to check in javascript that if that session is true i want to open a hidden div(make div display inline).How to do it using django.

4

1 回答 1

1

如果您有django.core.context_processors.request设置TEMPLATE_CONTEXT_PROCESSORS,您将可以访问request模板中的变量。

然后您可以request.session.edit_report在模板中分配一个 js 变量,如下所示:

<script type="text/javascript"> 
   var edit_report = {{ request.session.edit_report|yesno:"true,false" }};
</script>

然后edit_report在您的 javascript 代码中使用变量。

也可以看看:

希望有帮助。

于 2013-09-05T13:07:47.000 回答