12

I have a Django function "get_data_from_text_file()" that I want to test run from the command line. I tried:

>>> import v1.views
>>> get_data_from_text_file("kk")
Traceback (most recent call last):
  File "<input>", line 1, in <module>
NameError: name 'get_data_from_text_file' is not defined

Why is it not defined if its imported sucessfully?

5
  • 3
    Because that's not how Python modules work. Commented Oct 9, 2014 at 14:30
  • I'm kinda new to python, can you explain further, so I can test this function at the command line? Commented Oct 9, 2014 at 14:34
  • 2
    You'd probably want to run v1.views.get_data_from_text_file is my guess . . . Commented Oct 9, 2014 at 14:35
  • 3
    Keep in mind it won't work if it uses anything django related unless you run python manage.py shell and use that instead of your normal python shell. Commented Oct 9, 2014 at 14:36
  • thanks, it turned out to work when I used >>> v1.views.get_data_from_text_file("kk") Commented Oct 9, 2014 at 14:55

1 Answer 1

16

First of all make sure you're using manage.py shell and not plain python in the command line to make this test.

You're not importing the get_data_from_text_file function, but all the view. You could either use:

v1.views.get_data_from_text_file("kk")

or try to do the import like this:

from v1.views import get_data_from_text_file

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

Comments

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.