2013-09-25 32 views
5

我在我的virtualenv中安裝了ipython,所以python manage.py shell給了我的ipython。然而,我無法從內部函數定義訪問進口:爲什麼我不能使用ipython訪問Django shell中的導入函數?

$ python manage.py shell 
Python 2.7.5 (default, Sep 6 2013, 09:55:21) 
Type "copyright", "credits" or "license" for more information. 

IPython 1.1.0 -- An enhanced Interactive Python. 
?   -> Introduction and overview of IPython's features. 
%quickref -> Quick reference. 
help  -> Python's own help system. 
object? -> Details about 'object', use 'object??' for extra details. 

In [1]: from re import search 

In [2]: def my_search(pattern, string): 
    return search(pattern, string) 
    ...: 

In [3]: my_search('x', 'y') 
--------------------------------------------------------------------------- 
NameError         Traceback (most recent call last) 
/home/wilfred/.envs/drawbridge/lib/python2.7/site-packages/django/core/management/commands/shell.pyc in <module>() 
----> 1 my_search('x', 'y') 

/home/wilfred/.envs/drawbridge/lib/python2.7/site-packages/django/core/management/commands/shell.pyc in my_search(pattern, string) 
     1 def my_search(pattern, string): 
----> 2  return search(pattern, string) 
     3 

NameError: global name 'search' is not defined 

,如果我直接啓動ipython工作正常。爲什麼它不能在Django shell中工作?

回答

相關問題