-1

I have used a random function in python but its not working , I am very new at python. Please review below code

  def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['number'] = random.randrange(1, 100)
        return context

its rertuning error NameError: name 'random' is not defined

1 Answer 1

0

Probably, You did not import random module. Add this to the top of your script:

import random 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks its wrok fine. really appreciate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.