Commits

Branko Vukelic  committed e2ff54a

Added tips for Django

  • Participants
  • Parent commits ce9b153

Comments (0)

Files changed (1)

     >>> from mstranslator import MSTranslatorAccessKey
     >>> key = MSTranslatorAccessKey(client_id, client_secret)
 
+In Django, for example, you may create the key in the settings module, and make
+it available as a configuration setting::
+
+    # setup.py
+    import os
+    CLIENT_ID = os.environ.get('TRANSLATOR_ID')
+    CLIENT_SECRET = os.environ.get('TRANSLATOR_SECRET')
+    MS_TRANSLATOR_KEY = MSTranslatorAccessKey(CLIENT_ID, CLIENT_SECRET)
+
+    # somewhere in your view
+    from django.conf import settings
+    key = settings.MS_TRANSLATOR_KEY
+
+The key object has a ``get_key`` method which returns the cached key if it has
+not expired yet, shortening the response time. This method is used by the
+client object to retrieve the cached key, so you don't need to worry about the
+internal implementation.
+
 Creating the Microsoft Translator client object
 -----------------------------------------------