I kind of agree with James, but I think a) that the exception message is
not really self-explanatory and b) the instructions in the tutorial at this
point are somewhat unclear.

You started a plain Python shell with the command "python". You should have
used "python manage.py shell" instead, as was introduced in Part 2 of the
tutorial:

Now, let’s hop into the interactive Python shell and play around with the
> free API Django gives you. To invoke the Python shell, use this command:



$ python manage.py shell



We’re using this instead of simply typing “python”, because manage.py sets
> the DJANGO_SETTINGS_MODULE environment variable, which gives Django the
> Python import path to your mysite/settings.py file.
>

See
https://docs.djangoproject.com/en/2.0/intro/tutorial02/#playing-with-the-api

Hope that helps,
Daniel

On Wed, May 9, 2018 at 5:13 PM, James Farris <jamesafar...@gmail.com> wrote:

> Instead of giving the answer, I suggest looking at the Traceback section
> you posted below because the answer is there. Giving you the answer will
> not help your trouble shooting skills.
>
> Sent from my mobile device
>
> On May 9, 2018, at 8:03 AM, Avitab Ayan Sarmah <avitabay...@gmail.com>
> wrote:
>
>  shell
> <https://docs.djangoproject.com/en/2.0/ref/django-admin/#django-admin-shell>
> :
>
> >>> import datetime>>> from django.utils import timezone>>> from polls.models 
> >>> import Question>>> # create a Question instance with pub_date 30 days in 
> >>> the future>>> future_question = Question(pub_date=timezone.now() + 
> >>> datetime.timedelta(days=30))>>> # was it published recently?>>> 
> >>> future_question.was_published_recently()True
>
> Exceptions:
>
>
> PS C:\Users\AVITABAYAN\mysite> python
> Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:57:36) [MSC v.1900 64 bit 
> (AMD64)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import datetime
> >>> from django.utils import timezone
> >>> from polls.models import Question
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "C:\Users\AVITABAYAN\mysite\polls\models.py", line 7, in <module>
>     class Question(models.Model):
>   File "c:\python36\lib\site-packages\django\db\models\base.py", line 100, in 
> __new__
>     app_config = apps.get_containing_app_config(module)
>   File "c:\python36\lib\site-packages\django\apps\registry.py", line 244, in 
> get_containing_app_config
>     self.check_apps_ready()
>   File "c:\python36\lib\site-packages\django\apps\registry.py", line 127, in 
> check_apps_ready
>     raise AppRegistryNotReady("Apps aren't loaded yet.")
> django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
>
>
> models.py:
>
>
> import datetime
>
> from django.db import models
> from django.utils import timezone
>
>
> class Question(models.Model):
>     #...
>     def was_published_recently(self):
>         return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
>     def __str__(self):
>         return self.question_text
>     question_text = models.CharField(max_length=200)
>     pub_date = models.DateTimeField('date published')
>
> class Choice(models.Model):
>     #...
>     def __str__(self):
>         return self.choice_text
>     question = models.ForeignKey(Question, on_delete=models.CASCADE)
>     choice_text = models.CharField(max_length=200)
>     votes = models.IntegerField(default=0)
>
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@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/0801b9ea-0d71-4b96-9048-5f51e584a0ad%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/0801b9ea-0d71-4b96-9048-5f51e584a0ad%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@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/288685FE-5551-48B6-A70B-6A451D942B26%40gmail.com
> <https://groups.google.com/d/msgid/django-users/288685FE-5551-48B6-A70B-6A451D942B26%40gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/CAHEnUVWnAyzu7Z7-%3DQ-uimpPk6jKh%3Dw5PjOTZdiStF86mCTsGQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to