While going through the django tutorial i found error while scripting automated testing.The code and exeptions are mentioned below. Please find what is the error .

26 views
Skip to first unread message

Avitab Ayan Sarmah

unread,
May 9, 2018, 11:03:50 AM5/9/18
to Django users
 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)

James Farris

unread,
May 9, 2018, 11:14:05 AM5/9/18
to django...@googlegroups.com
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
--
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...@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/0801b9ea-0d71-4b96-9048-5f51e584a0ad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Hepper

unread,
May 9, 2018, 11:43:49 AM5/9/18
to django...@googlegroups.com
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.

Hope that helps,
Daniel 

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
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.
Reply all
Reply to author
Forward
0 new messages