try:
    SECRET_KEY
except NameError:
    from os.path import join
    from .base import BASE_DIR
    SECRET_FILE = join(BASE_DIR, 'secret.txt')
    try:
        SECRET_KEY = open(SECRET_FILE).read().strip()
    except IOError:
        try:
            import random
            SECRET_KEY = ''.join([random.SystemRandom().choice(
                'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)')
                for i in range(50)])
            secret = open(SECRET_FILE, 'w')
            secret.write(SECRET_KEY)
            secret.close()
        except IOError:
            Exception('Please create a {:s} file with random characters \
            to generate your secret key!'.format(SECRET_FILE))

try:
    SECRET_KEY
except NameError:
    from os.path import join
    from .base import BASE_DIR
    SECRET_FILE = join(BASE_DIR, 'secret.txt')
    try:
        with open(SECRET_FILE) as f:
            SECRET_KEY = f.read().strip()
    except IOError:
        try:
            import random
            SECRET_KEY = ''.join([random.SystemRandom().choice(
                'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)')
                for i in range(50)])
            secret = open(SECRET_FILE, 'w')
            secret.write(SECRET_KEY)
            secret.close()
        except IOError:
            Exception('Please create a {:s} file with random characters \
            to generate your secret key!'.format(SECRET_FILE))

Fix not closed file warning
fix: Fix not closed file warning

  try:
      SECRET_KEY
  except NameError:
      from os.path import join
      from .base import BASE_DIR
      SECRET_FILE = join(BASE_DIR, 'secret.txt')
      try:
+         with open(SECRET_FILE) as f:
-         SECRET_KEY = open(SECRET_FILE).read().strip()
+             SECRET_KEY = f.read().strip()
      except IOError:
          try:
              import random
              SECRET_KEY = ''.join([random.SystemRandom().choice(
                  'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)')
                  for i in range(50)])
              secret = open(SECRET_FILE, 'w')
              secret.write(SECRET_KEY)
              secret.close()
          except IOError:
              Exception('Please create a {:s} file with random characters \
              to generate your secret key!'.format(SECRET_FILE))
  
Fix not closed file warning
## Code Before:
try:
    SECRET_KEY
except NameError:
    from os.path import join
    from .base import BASE_DIR
    SECRET_FILE = join(BASE_DIR, 'secret.txt')
    try:
        SECRET_KEY = open(SECRET_FILE).read().strip()
    except IOError:
        try:
            import random
            SECRET_KEY = ''.join([random.SystemRandom().choice(
                'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)')
                for i in range(50)])
            secret = open(SECRET_FILE, 'w')
            secret.write(SECRET_KEY)
            secret.close()
        except IOError:
            Exception('Please create a {:s} file with random characters \
            to generate your secret key!'.format(SECRET_FILE))

## Instruction:
Fix not closed file warning
## Code After:
try:
    SECRET_KEY
except NameError:
    from os.path import join
    from .base import BASE_DIR
    SECRET_FILE = join(BASE_DIR, 'secret.txt')
    try:
        with open(SECRET_FILE) as f:
            SECRET_KEY = f.read().strip()
    except IOError:
        try:
            import random
            SECRET_KEY = ''.join([random.SystemRandom().choice(
                'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)')
                for i in range(50)])
            secret = open(SECRET_FILE, 'w')
            secret.write(SECRET_KEY)
            secret.close()
        except IOError:
            Exception('Please create a {:s} file with random characters \
            to generate your secret key!'.format(SECRET_FILE))
