-
Notifications
You must be signed in to change notification settings - Fork 853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solution.. Here we go again #796
base: master
Are you sure you want to change the base?
Conversation
taxi/urls.py
Outdated
@@ -1,4 +1,4 @@ | |||
from django.urls import path | |||
from django.urls import path, include |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need to change anything in this file - just revert
taxi/views.py
Outdated
def index(request): | ||
"""View function for the home page of the site.""" | ||
|
||
num_drivers = Driver.objects.count() | ||
num_cars = Car.objects.count() | ||
num_manufacturers = Manufacturer.objects.count() | ||
num_visits = request.session.get("num_visits", 0) | ||
request.session["num_visits"] = num_visits + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can add +1
in a statement above and then you will just need to pass num_visits without addition here and below
taxi_service/urls.py
Outdated
@@ -22,4 +22,5 @@ | |||
urlpatterns = [ | |||
path("admin/", admin.site.urls), | |||
path("", include("taxi.urls", namespace="taxi")), | |||
path("account/", include("django.contrib.auth.urls"), name="login"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need to set name="login")
here?
taxi/views.py
Outdated
num_visits = request.session.get("num_visits", 1) | ||
request.session["num_visits"] = num_visits + 1 | ||
|
||
context = { | ||
"num_drivers": num_drivers, | ||
"num_cars": num_cars, | ||
"num_manufacturers": num_manufacturers, | ||
"num_visits": num_visits + 1, | ||
"num_visits": num_visits, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how do you think, num_visits contains number or reference?
Because let's imagine that request.session.num_visits is 5
Then
num_visits = 5
request.session.num_visits = 6
then what is num_visits? 5 or 6? Does it contain reference to some object and number will be automatically updated to 6 or it just contains a number that won't be updated?
taxi/views.py
Outdated
num_manufacturers = Manufacturer.objects.count() | ||
num_visits = request.session.get("num_visits", 1) | ||
num_visits = request.session.get("num_visits", 0) | ||
request.session["num_visits"] = num_visits + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still wrong because you show the old number of visits. you show the previous number of views but when user opens the page it should display a new number
No description provided.