Skip to content

Instantly share code, notes, and snippets.

@bengolder
bengolder / csrf.js
Created December 9, 2014 19:34
Django REST Framework and CSRF protection for ajax posts.
var jQuery = window.$;
// using jQuery
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
@vstoykov
vstoykov / force_default_language_middleware.py
Last active June 6, 2024 10:51
Force Django to use settings.LANGUAGE_CODE for default language instead of request.META['HTTP_ACCEPT_LANGUAGE']
try:
from django.utils.deprecation import MiddlewareMixin
except ImportError:
MiddlewareMixin = object
class ForceDefaultLanguageMiddleware(MiddlewareMixin):
"""
Ignore Accept-Language HTTP headers