How to import and run django function on command line
I have a Django function "get_data_from_text_file ()" that I want to test and 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 undefined if imported successfully?
+3
source to share
1 answer
First of all, make sure you are using manage.py shell
and not just python
on the command line to perform this test.
You are not importing the get_data_from_text_file function, but the whole view. You can use:
v1.views.get_data_from_text_file ("kk")
or try importing like this:
from v1.views import get_data_from_text_file
+5
source to share