sunflower
sunflower copied to clipboard
Image gallery written in Python/Django
Sunflower
![]()
Sunflower is a simple image gallery written in Django framework. It strives to be easy to use and focus on presenting content in a clear and distraction-free fashion.
You can see working example under konradwasowicz.com/sunflower
Installation
This assumes you're using virtualenv for deployment
Setting up the project
- Create new virtualenv folder
virtualenv <project_name>
- Activate it:
# from within <project_name> folder
source bin/activate
- Clone sunflower repository:
git clone https://github.com/exaroth/sunflower.git
- Lastly install all the requirements:
# from within sunflower folder
pip install -r requirements.txt
- (Optional) Install memcached and run it on port 11211:
# for mac users
brew install memcached
# for linux users
sudo apt-get install memcached
Then run it:
memcached -d -p 11211
Note: Sunflower will still run even without memcached but the content won't be cached (d'oh).
Running development server
-
Inside
/static/directory executenpm install && bower installto download required Javascript libraries. -
Configure database settings inside
settings.pyfile and executepython manage.py syncdbto create required tables. -
Then edit
run_dev_server.shfile and changeDJANGO_DIRto an absolute path to your project (the directory withmanage.pyfile). -
Execute
run_dev_server.sh:
./run_dev_server.sh
This will start django dev server along with grunt and will compile less and refresh browser each time you make any changes to html, js or less files.
Running production server
This assumes you're using Nginx as a http server and Gunicorn as WSGI one.
-
Install gunicorn inside virtualenv and add it to
INSTALLED_APPSin settings.py -
IMPORTANT Change
SECRET_KEYvalue to anything you like. -
Add your hostname into
ALLOWED_HOSTSlist -
Define database backend inside
settings.py- see relevant entry in Django documentation for details. -
Execute
python manage.py syncdb. -
Go to
static/folder and executegrunt buildif you have made any changes to css or javascript, this will compile, concatenate and minify all the required files. -
Edit
run_sunflower.shscript, inside you will find following variables (starred entries should be changed):APP_NAME- name of the application- *
DJANGO_DIR- absolute path to the project - *
USER- define user account gunicorn process will be running as (preferablywww-data) - *
SOCKET_FILE- absolute path to unix socket file to be used withbindflag when running gunicorn server NUM_WORKERS- number of workers to be used by gunicornDJANGO_SETTINGS_MODULE- string denoting settings.py module inside the appDJANGO_WSGI_MODULE- same as above but for wsgi module
-
Then configure Nginx server to use gunicorn as reverse proxy. You can find example configuration that works fairly well in Gunicorn documentation. Be sure to add proper aliases for
staticandmediadirectories as files inside are served straight from hdd. -
Finally run memcached, execute
run_sunflower.shand restart Nginx with new configuration and you're set to go.