Skip to content
Advertisement

Django: ‘str’ object has no attribute ‘get’

I am trying to effectively make a Reddit clone just for practice with Django and I am trying to set up my upvote/downvote system with just a simple integer(upvote adds one, downvotes subtract one) however when I hit my “upvote” or “downvote” buttons it gives me the error 'str' object has no attribute 'get'. I have no idea what is causing this and all of the other answers with this error were not at all related, any help would be awesome. Full TraceBack:

JavaScript

My Model:

JavaScript

My Views:

JavaScript

My Urls:

JavaScript

My Feed.html(homepage):

JavaScript

Advertisement

Answer

In your views you write return reverse('feed-home') but this will return a string being the url of the url pattern named feed-home. A view should always be returning a response object. As a shortcut you can use the redirect [Django docs] to return a response which will redirect the user:

JavaScript

Note: Class names should ideally be in PascalCase not snake_case also function / variable names should be in snake_case not PascalCase. Hence instead of post your model should be named Post and instead of UpvoteView it should be upvote_view, etc. Have a look at PEP 8 — Style Guide for Python Code

Advertisement