Created
March 12, 2012 12:28
-
-
Save geoffalday/2021517 to your computer and use it in GitHub Desktop.
How to generate a secret key with Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to generate a secret key with Python | |
# via http://flask.pocoo.org/docs/quickstart/ | |
import os | |
os.urandom(24) |
For Python 2.X and Python 3.X
>>> import binascii >>> binascii.hexlify(os.urandom(24)) b'0ccd512f8c3493797a23557c32db38e7d51ed74f14fa7580'
Did you get any solution for this. I too facing the same issue
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello
Traceback (most recent call last):
File "manage.py", line 9, in
from solarpi.app import create_app
File "/home/amani/Desktop/new/solarpi/solarpi/app.py", line 10, in
from solarpi.settings import ProdConfig
File "/home/amani/Desktop/new/solarpi/solarpi/settings.py", line 7, in
class Config(object):
File "/home/amani/Desktop/new/solarpi/solarpi/settings.py", line 8, in Config
SECRET_KEY = os_env['SOLARPI_SECRET']
File "/home/amani/Desktop/new/.venv/lib/python2.7/UserDict.py", line 40, in getitem
raise KeyError(key)
KeyError: 'SOLARPI_SECRET'
and the following is my setting .py
mport os
os_env = os.environ
class Config(object):
SECRET_KEY = os_env['SOLARPI_SECRET']
APP_DIR = os.path.abspath(os.path.dirname(file)) # This directory
PROJECT_ROOT = os.path.abspath(os.path.join(APP_DIR, os.pardir))
BCRYPT_LOG_ROUNDS = 13
ASSETS_DEBUG = True
DEBUG_TB_ENABLED = True # Disable Debug toolbar
DEBUG_TB_INTERCEPT_REDIRECTS = True
CACHE_TYPE = 'simple' # Can be "memcached", "redis", etc.
SQLALCHEMY_TRACK_MODIFICATIONS = False
class ProdConfig(Config):
"""Production configuration."""
ENV = 'prod'
DEBUG = False
DB_NAME = 'app.db'
DB_PATH = os.path.join(Config.PROJECT_ROOT, DB_NAME)
SQLALCHEMY_DATABASE_URI = 'sqlite:///{0}'.format(DB_PATH)
DEBUG_TB_ENABLED = False # Disable Debug toolbar
SENTRY_DNS = os_env.get('SENTRY_DNS', None)
class DevConfig(Config):
"""Development configuration."""
ENV = 'dev'
DEBUG = True
DB_NAME = 'dev.db'
DB_PATH = os.path.join(Config.PROJECT_ROOT, DB_NAME)
SQLALCHEMY_DATABASE_URI = 'sqlite:///{0}'.format(DB_PATH)
DEBUG_TB_ENABLED = True
ASSETS_DEBUG = True # Don't bundle/minify static assets
CACHE_TYPE = 'simple' # Can be "memcached", "redis", etc.
class TestConfig(Config):
TESTING = True
DEBUG = True
SQLALCHEMY_DATABASE_URI = 'sqlite:///dev.db'
BCRYPT_LOG_ROUNDS = 1 # For faster tests
WTF_CSRF_ENABLED = False # Allows form testing
any idea how i can solve this