How to use both Django & NodeJS as backend for your application

The server part of library runs on top of NodeJS, which provides a high performance event-driven framework to manage the message exchange with client. All you need is a way to connect the socket.io server running on Node.JS with Django app. This can be easily done using Redis. Which is basically a key value store, but it also provides a way to subscribe and publish to keys, so it becomes a message bus with this architect socket.io server will subscribe a user specific keys, on to which Django is going to write a notification. Once the message is received, server will send it to the connected client.

.. Big names like Instagram and Pinterest are using both Django and NodeJS as a backend.

.. Instagram is the great example which run Django on Amazon High-CPU extra- large machine and as usage grows they gone from just a few of these machine to over 25 of them and a NodeJS server is used for sending a push notification. It aims at providing complete asynchronous client library for the API, including the REST search and streaming endpoint.

 

 

Hello, I’m Mr. Null. My Name Makes Me Invisible to Computers

This has all gotten to the point where I’ve developed a number of workarounds for times when this happens. Turning my last name into a combination of my middle name and last name, or middle initial and last name, sometimes works, but only if the website doesn’t choke on multi-word last names. My usual trick is to simply add a period to my name: “Null.” This not only gets around many “null” error blocks, it also adds a sense of finality to my birthright.

 

Django Rest Framework Permissions

The following is an example of a permission class that checks the incoming request’s IP address against a blacklist, and denies the request if the IP has been blacklisted.

<span class="kwd">from</span><span class="pln"> rest_framework </span><span class="kwd">import</span><span class="pln"> permissions

</span><span class="kwd">class</span> <span class="typ">BlacklistPermission</span><span class="pun">(</span><span class="pln">permissions</span><span class="pun">.</span><span class="typ">BasePermission</span><span class="pun">):</span>
    <span class="str">"""
    Global permission check for blacklisted IPs.
    """</span>

    <span class="kwd">def</span><span class="pln"> has_permission</span><span class="pun">(</span><span class="kwd">self</span><span class="pun">,</span><span class="pln"> request</span><span class="pun">,</span><span class="pln"> view</span><span class="pun">):</span><span class="pln">
        ip_addr </span><span class="pun">=</span><span class="pln"> request</span><span class="pun">.</span><span class="pln">META</span><span class="pun">[</span><span class="str">'REMOTE_ADDR'</span><span class="pun">]</span><span class="pln">
        blacklisted </span><span class="pun">=</span> <span class="typ">Blacklist</span><span class="pun">.</span><span class="pln">objects</span><span class="pun">.</span><span class="pln">filter</span><span class="pun">(</span><span class="pln">ip_addr</span><span class="pun">=</span><span class="pln">ip_addr</span><span class="pun">).</span><span class="pln">exists</span><span class="pun">()</span>
        <span class="kwd">return</span> <span class="kwd">not</span><span class="pln"> blacklisted</span>

 

User/IP Banning Middleware

Banning middleware with allow,deny functionality. Can select by User id/username and IP addresses. Returns a HttpResponseForbidden when banning requests. Banning by users is real nice because no matter which IP a pest comes from, they can never retrieve anything that they log into. Very handy for keeping out those unwanted pests! I personally developed this further to use a Ban model to keep track of different bans on different sites. Maybe ill post that eventually, but this runs as is with static vars. Implementation from HvZ Source