Two questions on Django Tutorial.

126 views
Skip to first unread message

SUBHABRATA BANERJEE

unread,
May 11, 2015, 12:35:39 PM5/11/15
to django...@googlegroups.com
Dear Group,

I am very new to Django, and started with Django on Windows. I am using Python 2.7.9. I have some
issues learning it.

(a) I was following the Tutorial given in
https://docs.djangoproject.com/en/1.8/intro/tutorial02/
It is generally going fine I am using, 1.8.1 of Django as given in
>>> django.get_version()
'1.8.1'
Here as I gave
python manage.py runserver
I could find the login page, http://127.0.0.1:8000/admin/ and could login using my login id and password.
But as I changed the admin.py with admin.site.register(Question) I could not find the changed view of the login page, rather it is
not coming anymore.

(b) I was trying to follow the earlier part of the Tutorial given in,
https://docs.djangoproject.com/en/1.8/intro/tutorial01/, things were generally fine,
but somehow I am failing to follow,
def __str__(self):              # __unicode__ on Python 2
        return self.question_text
in models.py, I am not being able to write models.py
So, if I use it as,
In [12]: Question.objects.all()
Out[12]: [<Question: Question object>]

In [13]: from polls.models import Question, Choice

In [14]: Question.objects.all()
Out[14]: [<Question: Question object>]

In [15]: Question.objects.filter(id=1)
Out[15]: [<Question: Question object>]

In [16]: Question.objects.filter(question_text__startswith='What')
Out[16]: [<Question: Question object>]

In [17]: from polls.models import Question, Choice

In [18]: Question.objects.all()
Out[18]: [<Question: Question object>]

In [19]: Question.objects.filter(id=1)
Out[19]: [<Question: Question object>]

I am not getting the desired output.

If any one may kindly suggest what is the error I am doing.

Thanks in advance,
Regards,
Subhabrata Banerjee.








 

Tim Graham

unread,
May 11, 2015, 1:32:50 PM5/11/15
to django...@googlegroups.com
You are using Python 2, but the tutorial is written for Python 3 as noted in part 1. If you aren't willing to switch to Python 3, you can rename the __str__ method to __unicode__ as the comment indicates.

SUBHABRATA BANERJEE

unread,
May 12, 2015, 6:09:25 AM5/12/15
to django...@googlegroups.com
Thanks Tim. It worked. Regards, Subhabrata Banerjee.
Reply all
Reply to author
Forward
0 new messages