Home > Blockchain >  Where do I find the default settings for my app in Django?
Where do I find the default settings for my app in Django?

Time:02-16

Problem: django.core.exceptions.ImproperlyConfigured: Requested settings, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

Example solution from Django Docs:

# Put this before accessing settings
from django.conf import settings

if not settings.configured:
      settings.configure(default_settings=myapp_defaults, DEBUG=True)

Okay but, where do I find my app's default settings?

My file structure is:

enter image description here

CodePudding user response:

By screenshot looks like you’re using PyCharm.

Do right click on the “second” charges from the screenshot and click on option “mark as sources root”

Then you’ll be be able to do what @raphael mentioned in the comment

Your settings are located under Charges/charges/charges/settings.py

Your interpreter does not see it because root is in Charges. Though, it should be also on Charges/charges to be able to import settings from it

CodePudding user response:

When you run Django through python manage.py runserver, your main project code (charges) is started and the settings.py is loaded. There, you should configure it globally. This default settings can be changed using env variables (if it sits somewhere else, or you want to try another settings.py file).

For your app/modules: create a settings.py and define your default there, then load in the apps.py the settings file like you did. Anyway, default would be overriden by your main settings.py

https://docs.djangoproject.com/fr/4.0/topics/settings/#custom-default-settings

  • Related