Skip to content

Instantly share code, notes, and snippets.

@sirodoht
sirodoht / django-csrf.js
Created November 7, 2017 15:25
Get CSRF token from Django HTML templates with vanilla JS
function getCsrf() {
var inputElems = document.querySelectorAll('input');
var csrfToken = '';
for (i = 0; i < inputElems.length; ++i) {
if (inputElems[i].name === 'csrfmiddlewaretoken') {
csrfToken = inputElems[i].value;
break;
}
}
return csrfToken;
@kalafut
kalafut / django_init
Last active June 15, 2024 02:44
Simple creation of a single-app django project
#!/bin/bash
#
# Simple creation of a single-app django project, as described in: https://zindilis.com/posts/django-anatomy-for-single-app/
#
# ./django_init foo
#
# This will result is the following flat structure:
#
# .
# └── foo