View gist:1536565
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
<VirtualHost *:80> | |
ServerName www.example.com | |
ServerAlias example.com | |
ServerAdmin webmaster@example.com | |
WSGIScriptAlias /cal /srv/http/caldav-to-gtasks/server.py | |
<Directory /srv/http/caldav-to-gtasks/> | |
AuthType Basic | |
AuthName "WSGI" |
View Simple Django URLs
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.conf.urls.defaults import patterns, include, url | |
urlpatterns = patterns('', | |
url(r'^(?P<input>[^/]+)$', 'UppercaseMaker.upper.views.home'), | |
) |
View Simple Django Template
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
<html> | |
<head><title>{{output}}</title></head> | |
<body> | |
Your output is: {{output}}. | |
</body> | |
</html> |
View Django Relative Template Directory
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 | |
TEMPLATE_DIRS = ( | |
os.path.join(os.path.dirname(__file__), 'templates'), | |
) |
View Simple Django View Response
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.shortcuts import render_to_response | |
def home(request, input="No input supplied"): | |
output = input.upper() | |
return render_to_response('home.html', {'output': output}) |
View gist:1296354
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
INSTALLED_APPS = ( | |
'django.contrib.auth', | |
'django.contrib.contenttypes', | |
'django.contrib.sessions', | |
'django.contrib.sites', | |
'django.contrib.messages', | |
# Uncomment the next line to enable the admin: | |
# 'django.contrib.admin', | |
# Uncomment the next line to enable admin documentation: | |
# 'django.contrib.admindocs', |
View Parsing HTML in Python
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 requests | |
import lxml | |
from lxml import html | |
r = requests.get('http://gun.io') | |
tree = lxml.html.fromstring(r.content) | |
elements = tree.get_element_by_id('frontsubtext') | |
for el in elements: | |
print el.text_content() |
View Parsing JSON in python
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 requests | |
import simplejson | |
r = requests.get('https://github.com/timeline.json') | |
c = r.content | |
j = simplejson.loads(c) | |
for item in j: | |
print item['repository']['name'] |
View POSTing using Python Requests
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 requests | |
url = 'https://testexample.com/form' | |
data={'title': 'RoboCop', 'description': 'The best movie ever.'} | |
r = requests.post(url, data=data) | |
print r |
View GET using Requests And Authentication
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 requests | |
r = requests.get('https://api.github.com', auth=('YOURUSERNAME', 'PASSWORD')) | |
print r |
NewerOlder