-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQIcBAEBCAAGBQJX8q1OAAoJEC0ft5FqUuEhgfsP/1B5ksGyFclhg7HsS6R92LOp
TLMlERd8MFc4w59hmAv1deMBzFE7x8582apObOoaqalu6v6ebx4hcWyY76aCI7hg
RTH7lqZihEbuzMsFO0Cale9V5NlgLpcaqowu5JOVPn4v2pjHSiiZNkjpMzo5kBAZ
uV4myw7TcVUI+ANy4TvWBb1hR2Ko5tuBwBU3n72lbQntZdt8X7ya6ZKeMxZRdD3D
xM2FEF0qILX19Ka+2p9nsHoOplfd6aeGFZ/Yga7xcVe456yNbumLonFtf6PG6Qm+
qhLYS3F+gxPjXjxfGtIU4kpdE/h3zsj8ySvjcsq48QQqKwzhAKlX+AnIrVq/BoH7
j9JhJft++wT6iI632nywiHwJ5wYWPW/babFAe/S7BSK6vuoulDQRw0hOso7UIVUi
QWg/lVyqHAprpX4tuMNaG44uuIFSveq7EZgK9PC/Cz/usnZ/g0EB8BQ3HSafBRlo
H52wVMoKhLSAQeCMo4zl7kT3WxmpI+xKDfUE58Xt74NMSNOpxphRLGciRnZlyfJ9
vh8ouLJL+QkRRE+/svZGR+6o9FoU3pef9yk1I7bt0gB3UsESL0zV2RLmPn71iqpE
nl3xWtkdJJ7enB3xnyRN3JHQ4zTRsv3JIUpW4l5eojHu6ua67wZgcceNRASEdmSb
Wa+s5Ahu9lYYwNt8kHXG
=4FCx
-----END PGP SIGNATURE-----
Hi Victor,
On 10/03/2016 01:06 PM, Victor Porton wrote:
> I've created an app which is "almost" reusable: it depends on a variable
> in <PROJ>/setting.py of our project <PROJ>.
>
> from <PROJ>.settings import TRANSACTION_ATTEMPT_COUNT
>
> Can it be made into an reusable app?
Certainly. Change the import to `from django.conf import settings`, so
you import the settings from Django rather than from your project (this
is generally the best way to access settings anyway). Then establish
some reasonable default value for the setting, and access it like
`getattr(settings, 'TRANSACTION_ATTEMPT_COUNT', default_value)`. Then
your app can work in any project, even if that project doesn't set a
value for that setting.
If there is no reasonable default value, and you want to force any
project using your app to set some value explicitly, you can also just
raise an error if the setting doesn't exist and in the exception message
instruct the developer that they must set the setting.
Carl
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/91f5fe1f-5436-13d1-dedf-6e48bf1dcab1%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment