background preloader

Setting up Django with Nginx, Gunicorn, virtualenv, supervisor and PostgreSQL - Michał Karzyński

Setting up Django with Nginx, Gunicorn, virtualenv, supervisor and PostgreSQL - Michał Karzyński
Django is an efficient, versatile and dynamically evolving web application development framework. When Django initially gained popularity, the recommended setup for running Django applications was based around Apache with mod_wsgi. The art of running Django advanced and these days the recommended configuration is more efficient and resilient, but also more complex and includes such tools as: Nginx, Gunicorn, virtualenv, supervisord and PostgreSQL. In this text I will explain how to combine all of these components into a Django server running on Linux. Prerequisites I assume you have a server available on which you have root privileges. If you don’t have a server to play with, I would recommend the inexpensive VPS servers offered by Digital Ocean. I’m also assuming you configured your DNS to point a domain at the server’s IP. Update your system Let’s get started by making sure our system is up to date. $ sudo aptitude update $ sudo aptitude upgrade PostgreSQL Application user Gunicorn Nginx Related:  ProgrammingStuffreads - Techdjango

Setting up an asynchronous task queue for Django using Celery and Redis - Michał Karzyński Celery is a powerful, production-ready asynchronous job queue, which allows you to run time-consuming Python functions in the background. A Celery powered application can respond to user requests quickly, while long-running tasks are passed onto the queue. In this article we will demonstrate how to add Celery to a Django application using Redis. Celery uses a broker to pass messages between your application and Celery worker processes. Prerequisites In this article we will add Celery to a Django application running in a Python virtualenv. This article was tested on a server running Debian 7, so everything should also work on an Ubuntu server or other Debian-based distribution. Update your system Let’s get started by making sure your system is up to date. $ sudo aptitude update $ sudo aptitude upgrade Install Redis The first piece of software we’ll install is Redis. $ sudo aptitude install redis-server $ redis-server --version Redis server version 2.4.14 (00000000:0) $ redis-cli ping PONG

Get A $100,000 Paying Engineering Job At Google By Mastering These 11 Tech Skills » TechWorm Who doesn’t want to work for a top tech company like Google? Not only is Google one of the top-most empathetic company in the world but it also pays it employees handsomely well. However, it is not that easy to get hired by the search giant. And it is no surprise. While interns here start at $70,000 to $90,000 salaries, the software engineers get $118,000 and senior software engineers earn an average of $152,985. You need skills and talent to get a job in Google. Thankfully for would-be Googlers, the Google in Education team has released a list of skills that they want to see in potential engineers. “Having a solid foundation in Computer Science is important in being a successful Software Engineer,” the company says. Here are the skills Google wants its tech talent to master, complete with online resources to get you started: 1. Try and get through an introduction to CS course, like the ones from Coursera or Udacity. 2. 3. 4. Add Java Script, HTML, CSS, and Ruby to the list of your skills.

Introduction | Django Girls Tutorial How to serve static files Django itself doesn’t serve static (media) files, such as images, style sheets, or video. It leaves that job to whichever Web server you choose. The reasoning here is that standard Web servers, such as Apache, lighttpd and Cherokee, are much more fine-tuned at serving static files than a Web application framework. With that said, Django does support static files during development. You can use the django.views.static.serve() view to serve media files. See also If you just need to serve the admin media from a nonstandard location, see the --adminmedia parameter to runserver. The big, fat disclaimer Using this method is inefficient and insecure. For information on serving static files in an Apache production environment, see the Django mod_python documentation. How to do it Here’s the formal definition of the serve() view: def serve(request, path, document_root, show_indexes=False) To use it, just put this in your URLconf: Given the above URLconf: STATIC_DOC_ROOT = '/path/to/media' Directory listings

Deploy Django on Apache with Virtualenv and mod_wsgi | The Code Ship I have recently got into Django and built a small project with it which is this blog. Then came the time for me to deploy the project on an unmanaged VPS, the process went fine yet with a few problems here and there due to the lack of a definitive guide to deployment. So I ended up checking several sources to have everything work the way I wanted. In this post, I'll be sharing the whole process with you in detail and what will hopefully be helpful to the fellow newcomers. Prerequisites In this tutorial we will assume that we have a fresh Ubuntu server installation with Python already installed and nothing else. Installing Pip Pip is a tool for installing and managing Python packages,basically a replacement for easy_install, many Python developers should be already familiar with it and have it already. $ sudo apt-get install python-pip python-dev build-essential Then upgrade to latest version $ sudo pip install --upgrade pip Setting up virtualenv $ pip install virtualenvwrapper Upload files

The Twelve-Factor App Finally, Real-Time Django Is Here: Get Started with Django Channels | Heroku Today, we're thrilled to host Jacob Kaplan-Moss. Jacob's a former Herokai and long-time core contributor to Django, and he's here to share an in-depth look at something that he believes will define the future of the framework. When Django was created, over ten years ago, the web was a less complicated place. The majority of web pages were static. The web circa 2016 is significantly more powerful. In this new world, Django shows its age. This doesn’t work with WebSockets! Thus: Django Channels. As you can see, Channels introduces some new concepts to Django: Channels are essentially task queues: messages get pushed onto the channel by producers, and then given to one of the consumers listening on that channel. Right now, Channels is available as a stand-alone app that works with Django 1.9. I believe that Channels will be an incredible imporant addition to Django: they allow Django to move smoothly into this new age of web development. First steps — it’s still Django Where we’re going 1.

How to use Django with Gunicorn Gunicorn (‘Green Unicorn’) is a pure-Python WSGI server for UNIX. It has no dependencies and is easy to install and use. There are two ways to use Gunicorn with Django. Installing Gunicorn Installing gunicorn is as easy as sudo pip install gunicorn. Running Django in Gunicorn as a generic WSGI application When Gunicorn is installed, a gunicorn command is available which starts the Gunicorn server process. gunicorn [OPTIONS] APP_MODULE Where APP_MODULE is of the pattern MODULE_NAME:VARIABLE_NAME. So for a typical Django project, invoking gunicorn would look like: gunicorn myproject.wsgi:application (This requires that your project be on the Python path; the simplest way to ensure that is to run this command from the same directory as your manage.py file.) Using Gunicorn’s Django integration Note If you are using Django 1.4 or newer, it’s highly recommended to simply run your application with the WSGI interface using the gunicorn command as described above. Having trouble?

Related: