Tutorial by Examples: c

Authentication can be set for an specific APIView endpoint, by using the authentication_classes variable: from rest_framework.authentication import SessionAuthentication, BasicAuthentication from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response ...
Django REST Framework provides a basic token-based authentication mechanism which needs to be configured as an application in Django before being usable, so that tokens are created in the database, and their lifecycle handled. Add Token-based authentication to settings.py INSTALLED_APPS = ( ...
OAuth is not handled by Django REST Framework, but there are a couple of pip modules that implement an OAuth client. The REST Framework documentation suggests one of the following modules: Django OAuth Toolkit Django REST Framework OAuth Django OAuth Toolkit pip install django-oauth-toolkit ...
The most interesting package for managing real tokens is django-rest-knox which supports multiple tokens per user (and cancelling each token independently), as well as having support for token expiration and several other security mechanisms. django-rest-knox depends on cryptography. You can find m...
A simple example of Vehicle hierarchy can be taken for single table inheritance strategy. Abstract Vehicle class: package com.thejavageek.jpa.entities; import javax.persistence.DiscriminatorColumn; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persi...
This sample uses a ToDataReader method described here Creating a Generic List DataReader for SqlBulkCopy. This can also be done using non-async methods. public class Widget { public int WidgetId {get;set;} public string Name {get;set;} public int Quantity {get;set;} } public as...
This sample uses a ToDataReader method described here Creating a Generic List DataReader for SqlBulkCopy. This can also be done using async methods. public class Widget { public int WidgetId {get;set;} public string Name {get;set;} public int Quantity {get;set;} } public void A...
Static initialization is suitable for most situations. When your application must delay the instantiation, use a non-default constructor or perform other tasks before the instantiation, and work in a multithreaded environment, you need a different solution. Cases do exist, however, in which you cann...
MongoDB.connect('mongodb://localhost:27017/databaseName', function(error, database) { if(error) return console.log(error); const collection = database.collection('collectionName'); collection.insert({key: 'value'}, function(error, result) { console.log(error, result); }); }...
const MongoDB = require('mongodb'); MongoDB.connect('mongodb://localhost:27017/databaseName') .then(function(database) { const collection = database.collection('collectionName'); return collection.insert({key: 'value'}); }) .then(function(result) { co...
You must always unregister scopes other then your current scope as shown below: //always deregister these $rootScope.$on(...); $scope.$parent.$on(...); You don't have to deregister listners on current scope as angular would take care of it: //no need to deregister this $scope.$on(...); $r...
<div class="container content"> <div class="row"> <!--Main Content--> <div class="col-lg-9 col-lg-push-3"> Main Content </div> <!--Sidebar--> <div class=&quot...
Rewrite Class File: Namespace/ModuleName/etc/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Ma...
Angular 2 has two kinds of custom validators. Synchronous validators as in the first example that will run directly on the client and asynchronous validators (the second example) that you can use to call a remote service to do the validation for you. In this example the validator should call the ser...
To detect a touch in Unity it's quite simple we just have to use Input.GetTouch() and pass it an index. using UnityEngine; using System.Collections; public class TouchExample : MonoBehaviour { void Update() { if (Input.touchCount > 0 && Input.GetTouch(0).phase == Touch...
$skuList = array('SKU-1', 'SKU-2',...,'SKU-n); $_productCollection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToFilter('sku', array('in' => $skuList)); OR $_productCollection = Mage::getResourceModel('catalog/product_collection') ->addAttributeToFilter('s...
find(query).projection(fields).cursorType(CursorType.TailableAwait).iterator(); That code applies to the MongoCollection class. CursorType is an enum and it has the following values: Tailable TailableAwait Corresponding to the old (<3.0) DBCursor addOption Bytes types: Bytes.QUERYOPTION...
This program will draw some shapes on the display, draw "hello world!" in the middle of the screen and let an image go to every corner of the window. You can use every image you want, but you will need to place the image file in the same directory as your program. the entire code: import...
These APIs are used to query for video and channel analytics, like views/clicks and votes.

Page 535 of 826