Skip to content
Advertisement

‘function’ object has no attribute ‘objects’ Django, help me

I’m designing a Django app and experiencing an error message:

JavaScript

This is my views.py that generates the message:

JavaScript

and this is my model.py

JavaScript

Thanks for any help.

Advertisement

Answer

You wrote a view function named Post, hence Post.objects refers to the Post function, not the model. You furthermore named your model posts, instead of Post. I strongly advise to rename your model to Post, since Django models are normally singular, and written in PerlCase:

JavaScript

Of course then you should rename the variables accordingly.

Advertisement