How to add object to users unique list?

30 views
Skip to first unread message

raf sandwich

unread,
Feb 28, 2022, 1:00:19 PM2/28/22
to Django users
Hi there. I have a system whereby users are recommended anime, and I want it so when they see anime on the website they can press a button on any anime shown, which will then add it to their 'UserList' which is a saved list that they can go back to and see whenever they want. 

I figure the button just needs to associate the anime.id with the POST request, and then add it to the user that is logged ins user.userlist.anime_in_list but I can't get it to work.

Currently my terminal is displaying the error

Method Not Allowed (POST): /anime/

Method not allowed: /anime/

when the button is pressed


A code break down for my models.py, views.py etc. is available on this reddit post:

https://www.reddit.com/r/djangolearning/comments/t3jwo0/how_to_add_an_object_to_a_users_list_without/

Thanks for any help I'm so stuck and I think it's probably simple!

Antonis Christofides

unread,
Mar 1, 2022, 1:52:04 AM3/1/22
to django...@googlegroups.com

Hello!

Are you using class-based views? Does your view have a post() method?

I searched the web for `django "method not allowed (POST)"` and this is the first result that came up:

https://stackoverflow.com/questions/52244156/method-not-allowed-post-in-django

Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/68c00521-21f5-4e15-a737-41edc42c11dfn%40googlegroups.com.

raf sandwich

unread,
Mar 1, 2022, 4:18:50 AM3/1/22
to Django users
Hi Antonis, 

Yes I saw that stackoverflow post also, but I was not able to resolve my issue with it. I do not need to update a model specific to the user when the user clicks a button, but I can't do it :(

David Crandell

unread,
Mar 1, 2022, 9:11:17 AM3/1/22
to Django users
Hello. You need a corresponding URL for your link that's why you're getting reverse error:

path('add/anime/<user>/<pk>/', views.MYVIEW, name='url-to-my-view'>

and then return redirect to your success_url after your enter the data, not return render.

raf sandwich

unread,
Mar 1, 2022, 10:50:48 AM3/1/22
to Django users
Hello. Thank you, I got it working! wooooooo :D

Joel Tanko

unread,
Mar 14, 2022, 9:41:49 AM3/14/22
to django...@googlegroups.com
What do you mean by click of a button? Are you using Ajax or a frontend framework?

You most likely aren't handling the post request on the view that's supposed to add the anime to the user's list


Reply all
Reply to author
Forward
0 new messages