Notes and anecdotes

Techstuff rambling

Django on Heroku with AWS S3 bucket for static and media files

Case: You want efficient collectstatic and serving of files You want static files and media files to be hosted on an AWS S3 bucket. (optional) You have too many files for “normal” collectstatic to be efficient. (optional) You have a non-US S3 bucket. (optional) You use Heroku Disclaimer: Have not tested with python 2.7, can’t…

Continue Reading

django rewrite / redirect to new urls

I changed the MEDIA_URL and STATIC_URL, but wanted the previously used urls “/media/” and “/static/” to rewrite to the new url. It would better be done via your DNS settings, or with an .htaccess file, but can also be done via if your circumstances don’t allow the other two. from django.conf import settings from django.views.generic.base import RedirectView […] if settings.MEDIA_URL…

Continue Reading

Show environment variables in Heroku

I was looking for WEB_CONCURRENCY environment variable on my Django-app. This is used for the number of concurrent webworkers for gunicorn, and is automatically scaled depending on the memory usage of your app. Do it with the toolbelt, and command heroku run printenv –app your-app-name | grep WEB_CONCURRENCY Read more on optimizing your app here

Export data from one Django to another over ssh

Sometimes I clone a repository with Django and make a setup of the environment on my own machine. Then I would usually like to have some testdata populated in my environment. So here’s how to copy the data from one Django installation (production) to my environment (test). 1. ssh to the remote server ssh username@hostname 2. Navigate to the folder…

Continue Reading

Django + Heroku bootstrap

It has happened on more than one occasion that I want a new Django project, with Grunt, jQuery, Bootstrap, Font-Awesome etc, deployed on Heroku. So I decided to write down the steps, and made a bash script to automate it all for me.

Django autocomplete in (virtualenv) shell

Create a file .pythonrc in ~/.pythonrc # enable syntax completion try: import readline except ImportError: print(“Module readline not available.”) else: import rlcompleter readline.parse_and_bind(“tab: complete”) Export it by adding this export to your profile file (if you use zsh, append to ~/.zprofile instead) echo “export PYTHONSTARTUP=~/.pythonrc” >> ~/.bash_profile Virtualenv Want it in virutalenv? Append it to your activate…

Continue Reading

Running Django with nginx (on webfaction)

Case: You’re using virtualenv and have used apache with a config somewhat like this. Problem: Apache ‘goes to sleep’ Apache caches your wsgi application, and if it’s not used within a certain amount of time, it has to reload. And this takes like.. 10-15 seconds. Solution: Use nginx instead: Set up a custom application, and install nginx + uwsgi to point to…

Continue Reading

Get python, pip, virtualenv without sudo

Case: You don’t have sudo and life is awful on a cheap VPS or similar. Step 1: Get your desired python version Python 2.7 cd mkdir python cd python mkdir src cd src wget tar xvfz Python-2.7.3.tgz cd Python-2.7.3 mkdir ~/python/python27 ./configure -prefix=/home/username/python/python27 make make install cd echo “export PATH=$HOME/python/python27/bin” >> .bashrc source .bashrc…

Continue Reading

No module named ‘_sqlite3’

TLDR: Try sudo apt-get install python-dev sudo apt-get install libsqlite3-dev And recompile python (see own post) Long version So, I was starting a django app (1.7.1 with Python 3.4), python migrate when i encountered django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named ‘_sqlite3’ Did not expect this. I have…

Continue Reading

pip on python3: Can’t decompress data; zlib not available

Getting pip3.4 to work Want Python3.4 on your debian with virtualenv and pip? That’s what I wanted. However, I didn’t get pip automatically, and when I tried to install it, python gave me “Can’t decompress data; zlib not available” Spent a whole lot of time on this. Seems like installing 3.4 properly (with –with-zlib parameter when configuring) makes…

Continue Reading