简体   繁体   中英

django runserver with webpack and reactjs project structure

I am trying to configure my tech stack of Django , webpack , and reactjs

Here is my project structure:

在此处输入图片说明

Right now I am getting this error when I run python manage.py runserver :

ImportError: No module named cherngloong.settings

Traceback:

    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

It is being caused by settings.py being in a different location.

I want to keep this structure of my project because I want to app directory to handle the front end and I want the server directory to handle the backend. How can I keep this structure but also be able to run the runserver command?

I looked within manage.py and I found this:

#!/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)

It seems to me that I need to change cherngloong.settings . I tried to change this to server.cherngloong.settings but I get the same error:

ImportError: No module named server.cherngloong.settings

You're trying to access the settings as if it is a module. To make that work, Python has to interpret both the server and chernloong directories as directories containing packages.

To do that, you have to create an __init__.py file in both directories. The file can be empty. What's __init__.py and what is it for?

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