background preloader

Django

Facebook Twitter

Etianen/django-require. Storing private files on Amazon S3 with Django and giving authorised users temporary access. It took me the best part of a day to piece together the parts of this so I thought they should all be in one place for the next person.

Storing private files on Amazon S3 with Django and giving authorised users temporary access

I can’t believe I found this so hard. I may have made mistakes, but it seems to work. I’m going to assume you’ve already got your site set up to store static files on S3 (which is particularly useful if, say, your site is hosted on Heroku). You should already have: Installed django-storages.Installed boto.Set up an AWS account and created a bucket in S3. Your media and static folders This isn’t essential for the whole private-files-on-S3 gist of this post, but getting your media and static files to end up on S3 in separate folders is a little non-obvious, but very useful. In your app create an s3utils.py file and put this in there: from storages.backends.s3boto import S3BotoStorage StaticS3BotoStorage = lambda: S3BotoStorage(location='static') MediaS3BotoStorage = lambda: S3BotoStorage(location='media') Making files private Allowing access to certain users.

Multiple email connections in Django. Using South for schema and data migrations in Django. South is a schema and data migrations for Django.

Using South for schema and data migrations in Django

In an easy way you may update your database tables after you change your models. It also keeps all migrations in the codebase allowing to migrate backward if needed. In this article I'll show some standard South usage cases. Installing and configuring South The quickest way to install south is to use pipL pip install South Next we have to add south to INSTALLED_APPS in your Django project. Basic usage Without south you would use syncdb to create table of your new models. Python manage.py schemamigration APPLICATION_NAME --initial In the application folder a "migrations" subfolder will be created. Python manage.py migrate APPLICATION_NAME If we would have such simple model: Get User from session key in Django. Get User from session key in Django 4 December 2008 Error emails contain session key When you get an error email from your Django app telling you someone got a server error, it’s not always easy to tell which user had a problem.

Get User from session key in Django

Optimiser ses applications Django — bruno.im. Prenons un exemple simple.

Optimiser ses applications Django — bruno.im

Supposons que vous avez ce modèle de données : class Article(models.Model): author = models.ForeignKey(User) title = models.CharField(max_length=255) Dans vos vues vous récupérez une liste d'articles : articles = Article.objects.all() Et dans les templates, vous affichez cette liste d'articles : {% for article in articles %} <h1>{{ article.title }}</h1><p>{{ article.content }}</p><p>{{ article.author.get_full_name }}</p>{% endfor %} Et là, on remarque qu'à chaque itération, une requête SQL supplémentaire est exécutée pour récupérer l'auteur de chaque article dans la base de données. Le problème vient du fait que Django a commencé par faire une requête SELECT sur les champs du modèle Article mais sans faire de jointure sur les tables voisines. Articles = Article.objects.select_related('author') Le fonctionnement de select_related() est intéressant. C'est un select_related() différent, celui-ci effectue deux requêtes mais pas de jointure.

Just managed to deploy @UniShared #django #python app on @Heroku (which is my first #Heroku's app) Just send my first #Tweet from the @UniShared's #Django backend thanks to #tweepy. Just send my first posts from the @UniShared's #Django backend, thanks to #django-facebook. Just integrate #django-facebook on @UniShared. Django. Planet Django. Planète django-fr. ★ Développer une application RESTful avec Django.

Après vous avoir expliqué la théorie sur l'architecture REST, rien de vaut un exemple concret pour bien comprendre le mécanisme.

★ Développer une application RESTful avec Django

J'ai longtemps hésité entre la classique todolist et un agrégateur pour l'exemple mais j'ai finalement opté pour ce dernier en souvenir d'un projet et pour en aider un autre qui va révolutionner votre notion de l'agrégation (ce sont eux qui le disent en tout cas...). Pour commencer un petit avertissement : cet exemple est très basique et ne développe ni toutes les possibilités de REST, ni toutes les fonctionnalités d'un agrégateur. Je souhaite juste montrer une implémentation possible avec Django de l'usage des verbes HTTP (GET, POST, PUT et DELETE) ;nous allons nous intéresser aux fils RSS et à leur maniement uniquement pour rendre l'exemple relativement générique.

Définition du protocole Nous allons suivre les 4 questions à se poser pour concevoir un protocole REST énoncées par Joe Gregorio : Quelles sont les URI ? Quels sont les formats ?