This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
project_dir = os.path.realpath(__file__) | |
sys.path.append(project_dir) | |
os.environ['DJANGO_SETTINGS_MODULE'] = 'main.settings' | |
import django | |
from django.conf import settings | |
django.setup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework.renderers import JSONRenderer | |
from rest_framework.response import Response | |
from rest_framework.views import APIView | |
class SimpleView(APIView): | |
renderer_classes = (JSONRenderer,) | |
permission_classes = (IsAuthenticated,) | |
def get(self, request): | |
content = {'testing': 123} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t = Template("The first stooge in the list is {{ stooges.0 }}.") | |
c = Context({"stooges": ["Larry", "Curly", "Moe"]}) | |
t.render(c) | |
#or if you want to render from an existing html template | |
from django.template.loader import render_to_string | |
rendered = render_to_string('my_template.html', context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git for-each-ref --sort=-committerdate refs/heads/ | |
#http://stackoverflow.com/questions/5188320/how-can-i-get-a-list-of-git-branches-ordered-by-most-recent-commit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
manage.py runserver --insecure | |
#http://stackoverflow.com/questions/5836674/why-does-debug-false-setting-make-my-django-static-files-access-fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#modified version off http://code.activestate.com/recipes/576602-safe-print/ | |
def sprint(*args, **kwargs): | |
"""Safely print the given string. | |
If you want to see the code points for unprintable characters then you | |
can use `errors="xmlcharrefreplace"`. | |
""" | |
errors = kwargs.get('errors', 'replace') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import connection | |
from django.db.backends.mysql.base import DatabaseOperations | |
def py_datetime_to_mysql(d): | |
db_ops = DatabaseOperations(connection) | |
return db_ops.value_to_db_datetime(d) | |
#eg: | |
from django.db import connection | |
py_datetime_to_mysql(datetime.now()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET foreign_key_checks = 0; | |
DELETE FROM users where id > 45; | |
SET foreign_key_checks = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE DATABASE some_db DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; |
OlderNewer