Skip to content
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

jQuery category like button doesn't work as expected #7

Open
piotrsynowiec opened this issue Jul 12, 2019 · 1 comment
Open

jQuery category like button doesn't work as expected #7

piotrsynowiec opened this issue Jul 12, 2019 · 1 comment

Comments

@piotrsynowiec
Copy link

On Django 2.2 this doesn't work as expected:

“Don’t forget to add in the URL mapping, into rango/urls.py. Update the urlpatterns by adding in:

path('like$', views.like_category, name='like_category'),”

I read the docs and tried this:
re_path(r'^like/$', views.like_category, name="like_category"),

and it kind of works, but after the first like, every time I refresh once liked category, refresh automatically adds +1 to the number of likes.

In the console it's visible that opening/refreshing the category is requesting 'like_category' view at the same time:

[12/Jul/2019 19:39:02] "GET /rango/like/?category_id=5 HTTP/1.1" 200 2
[12/Jul/2019 19:39:02] "GET /rango/category/python/ HTTP/1.1" 200 6311

@maxwelld90
Copy link
Collaborator

Hi Piotr,
Sounds strange. However, this is over the old version -- I fixed several things that were outstanding and it looks like this is one of them. The code above is a hangover from Django 1.9/1.10/1.11, where it uses regex to map patterns. So you are technically correct in trying re_path() to fix this issue.

However, I've updated the book since you reported this to use the following:

path('like_category/', views.LikeCategoryView.as_view(), name='like_category'),

Instructions have been updated to reflect this change in URL/name.

Not sure I can replicate the behaviour regarding multiple likes coming down on it when the page is refreshed? That is very strange. Again, code has been revised -- if you want to check our model solution on the new code GitHub, would you agree with what I have put in?

Cheers,
David

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants