2015-10-14 56 views
1

我想配置我的Djangowebpack技術堆棧,並reactjs用的WebPack和reactjs項目結構的Django的runserver

這裏是我的項目結構:

enter image description here

現在我得到我跑這個錯誤python manage.py runserver

ImportError: No module named cherngloong.settings

回溯:

Traceback (most recent call last): 
     File "manage.py", line 10, in <module> 
     execute_from_command_line(sys.argv) 
     File "/Users/bli1/Development/Django/CL/cherngloong/cherngloong/lib/python2.7/site-packages/django/core/management/__init__.py", line 351, in execute_from_command_line 
     utility.execute() 
     File "/Users/bli1/Development/Django/CL/cherngloong/cherngloong/lib/python2.7/site-packages/django/core/management/__init__.py", line 303, in execute 
     settings.INSTALLED_APPS 
     File "/Users/bli1/Development/Django/CL/cherngloong/cherngloong/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__ 
     self._setup(name) 
     File "/Users/bli1/Development/Django/CL/cherngloong/cherngloong/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup 
     self._wrapped = Settings(settings_module) 
     File "/Users/bli1/Development/Django/CL/cherngloong/cherngloong/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__ 
     mod = importlib.import_module(self.SETTINGS_MODULE) 
     File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module 
     __import__(name) 
    ImportError: No module named cherngloong.settings 

它被通過settings.py在不同的位置被引起的。

我想保留我的項目結構,因爲我想要app目錄來處理前端,我希望server目錄處理後端。我怎樣才能保持這種結構,但也能夠運行runserver命令?

我看着內manage.py,我發現這一點:

#!/usr/bin/env python 
import os 
import sys 

if __name__ == "__main__": 
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cherngloong.settings") 

    from django.core.management import execute_from_command_line 

    execute_from_command_line(sys.argv) 

在我看來,我需要改變cherngloong.settings。我試圖改變這server.cherngloong.settings但我得到了同樣的錯誤:

ImportError: No module named server.cherngloong.settings

+0

@Bjorn ahh youre – Liondancer

+0

@Bjorn如果你回答這個問題我會接受你的回答 – Liondancer

回答

1

你試圖訪問的設置,就好像它是一個模塊。爲了做到這一點,Python必須將serverchernloong目錄解釋爲包含目錄的目錄。

爲此,您必須在兩個目錄中創建__init__.py文件。該文件可以是空的。 What's __init__.py and what is it for?