Skip to content

Small mistake for value is not updated in code example #23260

@zx2020se

Description

@zx2020se

MDN URL

https://developer.mozilla.org/zh-CN/docs/Learn/Server-side/Django/Sessions

What specific section or headline is this issue about?

简单的例子 - 获取访问次数

What information was incorrect, unhelpful, or incomplete?

微信图片_20240812140401

in the example, it gets the value of num_visits and updates the value in session, while in the context, the value has not been updated

What did you expect to see?

def index(request):
    ...

    num_authors=Author.objects.count()  # The 'all()' is implied by default.

    # Number of visits to this view, as counted in the session variable.
    num_visits=request.session.get('num_visits', 0)
    request.session['num_visits'] = num_visits+1
    
    

    updated_num_visits = request.session.get('num_visits')


    # Render the HTML template index.html with the data in the context variable.
    return render(
        request,
        'index.html',
        context={'num_books':num_books,'num_instances':num_instances,'num_instances_available':num_instances_available,'num_authors':num_authors,
            'num_visits':updated_num_visits}, # use updated_num_visits
    )

Do you have any supporting links, references, or citations?

No response

Do you have anything more you want to share?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    l10n-koIssues related to Korean content.l10n-pt-brIssues related to Brazilian Portuguesel10n-zhIssues related to Chinese content.

    Type

    No type

    Projects

    Status

    Archive/Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions