Answer the question
In order to leave comments, you need to log in
Why doesn't the dictionary (context) pass to the template?
I want to display the number of page views. I can’t understand why the elements of the context dictionary are not displayed in the template.
views.py:
from django.shortcuts import render
def index(request):
num_visits = request.session.get('num_visits', 0) + 1
request.session['num_visits'] = num_visits
return render(request, 'hello/main.html', context = {"num_visits": num_visits, "ola": "lala",})
from django.urls import path
from . import views
app_name = 'hello'
urlpatterns = [
path('', views.index),
]
{% if ola %}<p>ola is running </p>{% else %}<p>It didn't work</p>{% endif %}
view count = {{ num_visits }}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question