pythonanywhere.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. if IN_PYTHONANYWHERE: # type: ignore
  2. # to use env variables on pythonanywhere
  3. # from dotenv import load_dotenv
  4. # project_folder = os.path.expanduser('/home/bakaabu')
  5. # load_dotenv(os.path.join(project_folder, '.env'))
  6. GOOGLE_OAUTH_URI = os.environ['GOOGLE_OAUTH_URI'] # type: ignore # "bakaabu.pythonanywhere.com"
  7. SECRET_KEY = os.environ['SECRET_KEY'] # type: ignore
  8. YOUTUBE_V3_API_KEY = os.environ['YOUTUBE_V3_API_KEY'] # type: ignore
  9. # WhiteNoise configuration
  10. assert MIDDLEWARE[:1] == [ # type: ignore # noqa: F821
  11. 'django.middleware.security.SecurityMiddleware'
  12. ] and not IN_DOCKER # type: ignore # PA does not support dockerized apps
  13. # Add whitenoise middleware after the security middleware
  14. MIDDLEWARE.insert(1, 'whitenoise.middleware.WhiteNoiseMiddleware') # type: ignore # noqa: F821
  15. # configure the domain name using the environment variable found on pythonanywhere
  16. ALLOWED_HOSTS = ['bakaabu.pythonanywhere.com', '127.0.0.1', 'untube.it']
  17. SITE_ID = 10
  18. CSRF_COOKIE_SECURE = True
  19. SESSION_COOKIE_SECURE = True
  20. SECURE_SSL_REDIRECT = True
  21. STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
  22. STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') # type: ignore
  23. # DBHOST is only the server name
  24. hostname = os.environ['DBHOST'] # type: ignore
  25. # Configure MySQL database on pythonanywhere
  26. # See https://django-mysql.readthedocs.io/en/latest/checks.html for options
  27. DATABASES = {
  28. 'default': {
  29. 'ENGINE': 'django.db.backends.mysql',
  30. 'NAME': f'{os.environ["DBUSER"]}${os.environ["DBNAME"]}', # type: ignore
  31. 'USER': f'{os.environ["DBUSER"]}', # type: ignore
  32. 'PASSWORD': f'{os.environ["DBPASS"]}', # type: ignore
  33. 'HOST': hostname,
  34. 'OPTIONS': {
  35. 'init_command': "SET sql_mode='STRICT_TRANS_TABLES', innodb_strict_mode=1",
  36. 'charset': 'utf8mb4',
  37. "autocommit": True,
  38. }
  39. }
  40. }
  41. print("Using Pythonanywhere settings...")