문제

I'm trying to use the command disqus_export.py from 'django-disqus' to export my comments from django.contrib.comments to disqus.

When I use disqus_export.py in my outer project folder(where manage.py is) I get the return:

Traceback (most recent call last):
  File "C:\Python27\Lib\site-packages\disqus\management\commands\disqus_export.p
y", line 5, in <module>
    from django.contrib import comments
  File "C:\Python27\lib\site-packages\django\contrib\comments\__init__.py", line
 4, in <module>
    from django.contrib.comments.models import Comment
  File "C:\Python27\lib\site-packages\django\contrib\comments\models.py", line 1
, in <module>
    from django.contrib.auth.models import User
  File "C:\Python27\lib\site-packages\django\contrib\auth\models.py", line 5, in
 <module>
    from django.db import models
  File "C:\Python27\lib\site-packages\django\db\__init__.py", line 11, in <modul
e>
    if DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "C:\Python27\lib\site-packages\django\utils\functional.py", line 184, in
inner
    self._setup()
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 40, in _set
up
    raise ImportError("Settings cannot be imported, because environment variable
 %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SE
TTINGS_MODULE is undefined.

As per the response in another similar question to, "Check this: python manage.py shell then import sys then sys.path. Is the project directory on that path? Exit out. Enter the regular python shell python. Then import sys, sys.path. Is the project directory on that path?,"

I did that and found that my project directory was returned by the first call but not the latter. However, the commenter who gave this instruction did not say what to do next, as the OP understood what he must do from there.

I assume I have to add my project directory to the latter sys.path, but I don't know how, so I'm hoping someone here can help me out.

도움이 되었습니까?

해결책

sys.path is just a list. The following does what you'd expect:

sys.path.append('/path/to/project')

Alternatively, you could set the PYTHONPATH environment variable to your project directory (or edit it to include it, if it already exists).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top