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+unsubscr...@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.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to