'NameError! I am following Django tutorial in part 5 when try to run test, getting error

[enter image description here][1]

[1]: https://i.stack.imgur.com/2wDSL.png NameError! I am following Django tutorial in part 5 when try to run test, getting error.



Solution 1:[1]

Make sure you have defined the function create_question above your test. In the tutorial (https://docs.djangoproject.com/en/4.0/intro/tutorial05/), the function looks like:

def create_question(question_text, days):
    """
    Create a question with the given `question_text` and published the
    given number of `days` offset to now (negative for questions published
    in the past, positive for questions that have yet to be published).
    """
    time = timezone.now() + datetime.timedelta(days=days)
    return Question.objects.create(question_text=question_text, pub_date=time)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SamSparx