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:
import urllib2 | |
from base64 import b64encode | |
request = urllib2.Request('https://api.xxxx.com/user') | |
request.add_header('Authorization', 'Basic ' + b64encode('user' + ':' + 'pass')) | |
r = urllib2.urlopen(request) | |
print r.getcode() | |
print r.headers["content-type"] | |
print r.headers["X-RateLimit-Limit"] |
import httplib | |
import xml.dom.minidom | |
HOST = "www.domain.nl" | |
API_URL = "/api/url" | |
def do_request(xml_location): | |
"""HTTP XML Post request""" | |
request = open(xml_location, "r").read() |
import base64 | |
""" | |
Some useful functions for interacting with Java web services from Python. | |
""" | |
def make_file_java_byte_array_compatible(file_obj): | |
""" | |
Reads in a file and converts it to a format accepted as Java byte array | |
:param file object |
import sys; print('Python %s on %s' % (sys.version, sys.platform)) | |
import django; print('Django %s' % django.get_version()) | |
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS]) | |
if 'setup' in dir(django): django.setup() | |
import django_manage_shell; django_manage_shell.run(PROJECT_ROOT) |
import sys | |
import logging | |
logging.basicConfig(format="%(levelname)-8s %(asctime)s %(name)s %(message)s", datefmt='%m/%d/%y %H:%M:%S', stream=sys.stdout ) | |
log = logging.getLogger("root") | |
from django.db.models import get_models | |
from django.conf import settings | |
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned | |
logging.config.dictConfig(settings.LOGGING) |
import sys | |
import django | |
django.setup() | |
from django.db.models import get_models | |
for _class in get_models(): | |
globals()[_class.__name__] = _class |
Working in a Python project, it's common to have a clean-up step that deletes all the .pyc files, like this: | |
$ find . -name '*.pyc' -delete | |
This works great, but there's a slight chance of a problem: Git records information about branches in files within the .git directory. These files have the same name as the branch. | |
Try this: | |
$ git checkout -b cleaup-all-.pyc |
#!/bin/bash | |
# Script author: MrVaykadji http://askubuntu.com/users/176689/mrvaykadji | |
# Changes made by Ribtoks | |
# - simulink for compass2.0 in /usr/bin/ | |
# - replaced apt commands with zypper commands | |
# Changes made by Andrew <[email protected]>: | |
# - use the NodeJS PPA to avoid build failure with grunt-cli | |
# - use the Popcorn Time icon | |
# - added check for apt, dpkg, etc. | |
# - added some checks when creating symbolic links |
#!/bin/bash | |
find . -name "*.pyc" -exec git rm {} \; | |
git commit -m "Removed compiled python files in distribution left after last commit" |