You have just decided to use Celery into your Django project and configured it already. All tasks are now created and are running correctly. So you deploy it on a server. Only issue is that logs will refuse to appear in your application server logs and you are losing any log capture for your celery workers.

Worry not! here is a production tested config for you so that your celery logs appear in your server logs in all their glory.

If not already follow my previous guide on how to do Django logging properly. …


If you are working on Django, you might have faced difficulty in configuring logging with a dict in settings.py file. You go about writing your dict but your values are not valued and have no effect.

Image for logging config done right

There is a very simple solution for this problem and that is properly overriding the logging config so that whatever Django has already configured is replaced with your own best in class(atleast for you) logging config.

To provide a wholesome example, The above config is using such awesome projects as colorlog(errors will be red and warnings will be yellow etc), django-log-request-id(append a unique…


Once your site goes live there are some elements out there who keep trying to access your filesystem using an old UNIX hack of trying to hit your site with a path to sock file. Using frameworks like Django can prevent this already if you have your DISALLOWED_HOST settings set properly to only allow valid hostnames in it. But the first line of defense for this must be the webserver i.e. Nginx. The assumption being here that you are using Nginx as your reverse proxy server.

Depending on your configuration your conf files for Nginx will be in either /etc/nginx/conf.d/


Django Rest Framework(DRF) makes it simple to create usual paginated responses for you by just using a ModelSerializer and ModelViewSet. For example you can easily create a response like this:

{
"count": 23,
"next": null,
"previous": null,
"results": [
... Your favorite kitten shoes list ...
]
}

This is all good and dandy, but what if you want more fields added other than and outside of just the results serialized by your serializer.

Mind that something similar can also be achieved by using a serializer but serializer won’t be able to help when you want access to request object…

Siddharth Pant

Always learning.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store