Dave
Dave

Reputation: 19220

How do I import constants from my settings.py file into my Django console?

I'm using Python 3.7 with Django. I have this at the end of my settings.py file

MAX_AGE_IN_HOURS = 18

When I fire up my console, how do I get this constant recognized? I have tried teh below, but get an error complaining that the above is not defined.

from django.conf import settings
(age.seconds / 3600) > MAX_AGE_IN_HOURS
Traceback (most recent call last):
  File "<input>", line 1, in <module>
NameError: name 'MAX_AGE_IN_HOURS' is not defined

Upvotes: 1

Views: 143

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599778

This is standard Python semantics; you imported settings, so you need to access the values via that name.

(age.seconds / 3600) > settings.MAX_AGE_IN_HOURS

Upvotes: 2

Related Questions