django : Serving static files through nginx

I think using root in location block is incorrect. I use alias and it works fine, even without re-configuring django. # django settings.py MEDIA_URL = ‘/static/’ # nginx server config server { … location /static { autoindex on; alias /opt/aa/webroot/; } } Hope this makes things simpler.

How can I test binary file uploading with django-rest-framework’s test client?

When testing file uploads, you should pass the stream object into the request, not the data. This was pointed out in the comments by @arocks Pass { ‘image’: file} instead But that didn’t full explain why it was needed (and also didn’t match the question). For this specific question, you should be doing from PIL … Read more

Django Migrations Add Field with Default as Function of Model

I just learned how to do this with a single migration! When running makemigrations django should ask you to set a one-off default. Define whatever you can here to keep it happy, and you’ll end up with the migration AddField you mentioned. migrations.AddField( model_name=”series”, name=”updated_as”, field=models.DateTimeField(default=????, auto_now=True), preserve_default=False, ), Change this one operation into 3 … Read more

User groups and permissions

Django has a built in groups system. Whenever you have a question like this, I recommend searching the Django docs, which are extensive, helpful, and well written. So long as you are using the django.contrib.auth app, you have access to groups. You can then assign permissions to those groups. from django.contrib.auth.models import User, Group, Permission … Read more

110: Connection timed out (Nginx/Gunicorn)

You could try upgrading the timeout for your proxy pass in Nginx by adding: proxy_connect_timeout 75s; proxy_read_timeout 300s; on /var/nginx/sites-available/[site-config] or /var/nginx/nginx.conf if you want to increase the timeout limite on all sites served by nginx. You must add –timeout 300 as well to your gunicorn process/config. This solved my problems in the past with … Read more

Django / Comet (Push): Least of all evils?

I’d take a look at evserver (http://code.google.com/p/evserver/) if all you need is comet. It “supports [the] little known Asynchronous WSGI extension” and is build around libevent. Works like a charm and supports django. The actual handler code is a bit ugly, but it scales well as it really is async io. I have used evserver … Read more

How to pass extra context to Django Rest Framework serializers

You have to use get_object as func, not as property: class PostViewSets(viewsets.ModelViewSet): queryset = Post.objects.all() serializer_class = PostSerializer def get_serializer_context(self): context = super(PostViewSets, self).get_serializer_context() author = self.get_object().author author_posts = self.get_queryset().filter(author=author) context.update({‘author_posts’: author_posts}) return context

Host Django on subfolder

My comment doesn’t show the whole picture. When I’ve run Django sites on subfolders, I like to use a dynamic config so that you can still access the machine directly (without the proxy) and have a working web-app. This can help a LOT for debugging tricky stuff like this that is hard to reproduce in … Read more