type object 'Story' has no attribute 'object'

24 views
Skip to first unread message

harsh sharma

unread,
Sep 11, 2017, 10:21:10 AM9/11/17
to Django users
why i m getting this
error  :-type object 'Story' has no attribute 'object'


this is my views.py file:
from django.shortcuts import render,render_to_response
from django.http import HttpResponseRedirect
from django.template import RequestContext
from .models import *
from django.http import HttpResponse,HttpRequest
# Create your views here.



def home(request):

story = Story.object.all()
return render_to_response('show.html',{'story':story})


this is my models.py file:

from django.db import models
from django.forms import ModelForm;
# Create your models here.

class Story(models.Model):
stories = models.CharField(max_length=1024)


class storyform(ModelForm):
class Meta:
model = Story
fields = ['stories']



James Schneider

unread,
Sep 11, 2017, 10:34:27 AM9/11/17
to django...@googlegroups.com


On Sep 11, 2017 7:20 AM, "harsh sharma" <harshsha...@gmail.com> wrote:
why i m getting this
error  :-type object 'Story' has no attribute 'object'


this is my views.py file:
from django.shortcuts import render,render_to_response
from django.http import HttpResponseRedirect
from django.template import RequestContext
from .models import *
from django.http import HttpResponse,HttpRequest
# Create your views here.



def home(request):

story = Story.object.all()
return render_to_response('show.html',{'story':story})



The first line of your home() view should be this:

    story = Story.objects.all()

The default model manager creates an 'objects' attribute that is plural.

-James

SHAILESH NEGI

unread,
Sep 11, 2017, 1:26:57 PM9/11/17
to django...@googlegroups.com
objects it is

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/711b4bc2-c974-46f7-a88b-d90ad561d92f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Thanks & Regards,
SHAILESH NEGI


harsh sharma

unread,
Sep 11, 2017, 5:10:33 PM9/11/17
to Django users
Thanks for helping 
Reply all
Reply to author
Forward
0 new messages