Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I reference a Django settings variable in my models.py?

People also ask

How do you add settings py to Django?

Take a default settings.py from an new project. Locate the requirements. txt and verify which one of the apps located there are django base and include them to the settings.py. Include all the apps explicitly defined on the project (all the folders different to the appname folder)

Where do I put settings py?

Create a settings.py file in your application's package (for example, if your application is named "myapp", put it in the filesystem directory named myapp ; the one with an __init__.py in it.

Where is Django settings file?

A Django settings file doesn't have to define any settings if it doesn't need to. Each setting has a sensible default value. These defaults live in the module django/conf/global_settings.py .

What does settings py do in Django?

The settings.py is the central configuration for all Django projects. In previous chapters you already worked with a series of variables in this file to configure things like Django applications, databases, templates and middleware, among other things.


Try with this: from django.conf import settings then settings.VARIABLE to access that variable.

VARIABLE should be in capital letter. It will not work otherwise.


from django.conf import settings

PRIVATE_DIR = getattr(settings, "PRIVATE_DIR", None)

Where it says None, you will put a default value incase the variable isn't defined in settings.