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

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

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