This document has now been incorporated into the uWSGI documentation:
http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html
Steps with explanations to set up a server using:
from jinja2 import BytecodeCache | |
class RedisTemplateBytecodeCache(BytecodeCache): | |
'''Implements a Jinja2 bytecode cache on top of a pyredis.StrictRedis | |
connection | |
See: http://jinja.pocoo.org/docs/2.10/api/#bytecode-cache | |
''' | |
def __init__(self, redis_cnx, template_cache_key_prefix=None, ttl=86400): |
require 'date' | |
module Nordea | |
module NDA | |
class Record | |
def self.parse(str) | |
self.new(str).normalized | |
end | |
def initialize(str) |
[ | |
{ | |
"pk": 1, | |
"model": "blog.blogpost", | |
"fields": { | |
"status": 2, | |
"expiry_date": null, | |
"allow_comments": true, | |
"description": "This is an example of a blog post.", | |
"title": "example blog post", |
server { | |
listen 80; | |
server_name blog; | |
server_name blog.example.com; | |
root /var/www/blog; | |
location /static/ { | |
alias /var/www/blog/static/; | |
expires 30d; | |
access_log off; |
[uwsgi] | |
# Variables | |
base = /var/www/blog | |
app = simple | |
# Generic Config | |
plugins = http,python | |
home = %(base)/venv | |
pythonpath = %(base) | |
socket = /var/www/run/%n.sock | |
module = %(app) |
description "uWSGI" | |
start on runlevel [2345] | |
stop on runlevel [06] | |
respawn | |
env UWSGI=/usr/bin/uwsgi | |
env LOGTO=/var/log/uwsgi/emperor.log | |
exec $UWSGI --master --emperor /etc/uwsgi/apps-enabled --die-on-term --uid nginx --gid nginx --logto $LOGTO |
#!/bin/bash | |
# | |
# Shell script to automatically configure a new Flask, nginx and uWSGI based blog | |
# on an Amazon EC2 instance. | |
# | |
# See http://bit.ly/MeGwjD for more information! | |
# | |
# If you are forking this for your own custom configuration script, see the following other gists: | |
# https://gist.github.com/3071737 | |
# https://gist.github.com/3071739 |
from random import choice | |
from string import ascii_lowercase, digits | |
from django.contrib.auth.models import User | |
def generate_random_username(length=16, chars=ascii_lowercase+digits, split=4, delimiter='-'): | |
username = ''.join([choice(chars) for i in xrange(length)]) | |
if split: | |
username = delimiter.join([username[start:start+split] for start in range(0, len(username), split)]) |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!