简体   繁体   中英

Why can I import a library from the Django shell, but not inside my site?

I am trying to use the oauth2app library inside my Django app. I've tried installing the library several ways (easy_install, pip, pip via a requirements file, etc.), and every time it installs just fine. Also every time I can import the library from the Django shell (manage.py shell).

However, when I try to use a view from the library:

(r'^oauth2/token/?$', 'oauth2app.token.handler'),

I get a "No module named oauth2app" import error. I've tried comparing the Python path from the Django debug page to the one from "print sys.path" inside the shell, and the seem to be the same, so I can't for the life of me figure out why one works and the other doesn't.

Can anyone help explain what's going on? I thought the Django shell was an equivalent environment to the Django instance ...

Nevermind, it looks like this was just a case of bad documentation on the library's site; when I changed the urls.py line to:

from oauth2app import token
...
(r'^oauth2/token/?$', token.handler),

it worked, sigh .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM