django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured

前端 未结 8 1332
你的背包
你的背包 2021-02-18 18:07

I\'m trying to run a populate script which I put together from the tango_with_django tutorial (https://github.com/leifos/tango_with_django/blob/master/tango_with_django_project/

相关标签:
8条回答
  • 2021-02-18 18:45

    Call to django.setup() should go after setting DJANGO_SETTINGS_MODULE environment variable. Just move it into your __main__ right after os.environ.setdefault().

    0 讨论(0)
  • 2021-02-18 18:46
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'epl.settings')
    

    should be above

    import django
    

    which is you should call django_settings_module before importing and calling django setup.

    Hope this is helpful.

    0 讨论(0)
  • 2021-02-18 18:50

    For development and debugging, you may use the standalone python package.

    Install with pip

    pip install standalone
    

    Use standalone to use Django from the module.

    # add the following to the top of the module.
    import standalone
    standalone.run('mysite.settings') # replace with your settings module.
    
    # your code goes below the configuration
    import os
    import sys
    
    # ... .. .  whole module
    

    Now you may run the module as a Python Django script.

    0 讨论(0)
  • 2021-02-18 18:51

    You can insert os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") before the django.setup() line.

    0 讨论(0)
  • 2021-02-18 18:52

    If you are getting a similar error after initiating your interaction with Django by running python in a terminal, running python manage.py shell in the appropriate directory may solve your issue.

    0 讨论(0)
  • 2021-02-18 18:54

    I met the same problem when setting the environment.

    (I tried to add the:

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_project.settings")
    

    into the "Starting script window",which is in the Django Console or rewrite the .wsgi file, But all of them were failed)

    My final solution: (open the terminal and set the environment manually)

    Here are the steps:(for mac)

    1. open the terminal and type vim ~/.bash_profile

    2. add below lines:

       PATH=${PATH}:/Users/work/workspace/[virtual_environment]/bin
       PYTHONPATH=${PATH}:/Users/work/PycharmProjects/[project_name]
       DJANGO_SETTINGS_MODULE=[project_name].settings
      
    3. type :wq to save and exit terminal

    4. type source ~/.bash_profile to reload it

    it will work when you run python manage.py shell this time.

    0 讨论(0)
提交回复
热议问题