Guest User

Untitled

a guest
Jan 18th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. f = Flask(__name__)
  2.  
  3. # 'TheFuture' is the name of my laptop. It signifies that we are in
  4. # development mode.
  5. if socket.gethostname().startswith('TheFuture'):
  6. f.config.from_object('config.DevelopmentConfig')
  7. # If 'TheFuture' isn't the host, then we are in production.
  8. else:
  9. f.config.from_object('config.ProductionConfig')
  10.  
  11. # MongoDB connection
  12. connection = Connection(f.config['MONGODB_HOST'], f.config['MONGODB_PORT'])
  13. db = connection['MONGODB_DB']
  14.  
  15. # Try authenticating. This will only work in production. In development,
  16. # MONGODB_USER and MONGODB_PASSWORD will raise KeyErrors.
  17. try:
  18. db.authenticate(f.config['MONGODB_USER'], f.config['MONGODB_PASSWORD'])
  19. except KeyError:
  20. pass
  21.  
  22. class Config(object):
  23. '''Default configuration object.'''
  24. DEBUG = False
  25. TESTING = False
  26. PORT = int(os.environ.get('PORT', 5000))
  27.  
  28. class ProductionConfig(Config):
  29. '''Configuration object specific to production environments.'''
  30. REDIS_URL = os.environ.get('REDISTOGO_URL')
  31. if REDIS_URL:
  32. url = urlparse.urlparse(REDIS_URL)
  33. REDIS_HOST = url.hostname
  34. REDIS_PORT = url.port
  35. REDIS_PASSWORD = url.password
  36.  
  37. MONGOLAB_URI = os.environ.get('MONGOLAB_URI')
  38. if MONGOLAB_URI:
  39. url = urlparse.urlparse(MONGOLAB_URI)
  40. MONGODB_USER = url.username
  41. MONGODB_PASSWORD = url.password
  42. MONGODB_HOST = url.hostname
  43. MONGODB_PORT = url.port
  44. MONGODB_DB = url.path[1:]
  45.  
  46. class DevelopmentConfig(Config):
  47. '''Configuration object specific to development environments.'''
  48. DEBUG = True
  49.  
  50. MONGODB_HOST = 'localhost'
  51. MONGODB_PORT = 27017
  52. MONGODB_DB = 'twitter-clone-python-development'
  53.  
  54. 2012-09-28T13:57:25+00:00 app[web.1]: pymongo.errors.AutoReconnect: could not connect to ds037997.mongolab.com:27017: timed out
Add Comment
Please, Sign In to add comment