Description
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?

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
Labels
Type
Projects
Status
Archive/Closed