简体   繁体   中英

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

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

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