简体   繁体   中英

Import Error: No module named http django

I have an error occurring in my wsgi.py file. It's complaining that:

File "(directory)/.local/lib/python2.7/site-packages/Django-1.5 py2.7.egg/django/core/handlers/wsgi.py", line 9, in <module>
    from django import http
ImportError: cannot import name http

I checked that the directory http exists in (directory)/.local/lib/python2.7/site-packages/Django-1.5 py2.7.egg/django/. Also, when importing django.core, there is no problem, but when importing any of the other modules, it gives the same error. Here is the directory information for (directory)/.local/lib/python2.7/site-packages/Django-1.5 py2.7.egg/django/:

django:
    bin  conf  contrib  core  db  dispatch  forms  http  __init__.py  __init__.pyc  middleware  shortcuts  template  templatetags  test  utils  views

And here's the directory info for http:

http:
    cookie.py  cookie.pyc  __init__.py  __init__.pyc  multipartparser.py  multipartparser.pyc  request.py  request.pyc  response.py  response.pyc  utils.py  utils.pyc

EDIT:

error given in python shell:

>>from django import http
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name http

>>from django import core
>>

Error was solved by deleting a local directory also called django. However, the local directory was in place because I am putting my site on a shared server that I cannot edit the site-packages of. Is there a way for the application to read both from my local and the server's django folders so that I can use modules that are not on the server's django directory?

You can turn your local django folder into a namespace. This tells the python interpreter to continue traversing the path for modules, even if it finds a matching module earlier (ie the 'django' module you added).

Add this to the __init__.py in your local django folder:

import pkg_resources
pkg_resources.declare_namespace(__name__)

When python finds this module, it runs this code to register it as a namespace.

您需要设置PYTHONPATH环境变量以指向您的本地模块。

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