brew install python
OR
brew update
brew upgrade python3
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
DATABASE_URL="postgresql:///blog"
MAIL_SERVER= localhost
MAIL_PORT=8025
SECRET_KEY=a-really-long-and-unique-key-that-no-one-knows
ELASTICSEARCH_URL=http://localhost:9200
flask run
brew install postgresql
To migrate existing data from a previous major version of PostgreSQL run:
brew postgresql-upgrade-database
To have launchd start postgresql now and restart at login:
brew services start postgresql
Or, if you don't want/need a background service you can just run:
pg_ctl -D /usr/local/var/postgres start
Be sure to install and start Elasticsearch!
brew tap elastic/tap
brew install elastic/tap/elasticsearch-full
elasticsearch
brew update
brew install redis
To have launchd start redis now and restart at login:
brew services start redis
to stop it, just run:
brew services stop redis
Or, if you don't want/need a background service you can just run:
redis-server /usr/local/etc/redis.conf
flask shell
Running migrations
Create an env.py
file from the example in the migrations folder
If flask db migrate
fails, try to delete the latest migration file ( a python file) then try to perform a migration afresh.
If issue still persists try these commands :
flask db stamp head # To set the revision in the database to the head, without performing any migrations. You can change head to the required change you want.
flask db migrate # To detect automatically all the changes.
flask db upgrade # To apply all the changes.
Generate a new migration
flask db migrate -m "migration message"
Apply it to the database
flask db upgrade
If you see the dreaded "RuntimeError: Working outside of application context." error:
>>> from app import create_app
>>> app = create_app()
>>> app.app_context().push()
>>> current_app.config['SQLALCHEMY_DATABASE_URI']
'sqlite:////your/cool/uri'
export FLASK_DEBUG=0
export MAIL_SERVER=localhost
export MAIL_PORT=8025
python -m smtpd -n -c DebuggingServer localhost:8025
flask translate init LANG
to add a new language
flask translate update
to update all the languages after making changes to the _() and _l() language markers
flask translate compile
to compile all languages after updating the translation files
createdb <database_name>
createdb my_database
psql -U postgres -l
psql -U postgres -d <database_name>
psql -U postgres -d my_database
dropdb <database_name>
dropdb my_database
dropdb <database_name> && createdb <database_name>
dropdb my_database && createdb my_database