Skip to content

fix django1.8 HttpResponse compatibility #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -4,3 +4,4 @@
MANIFEST

dist/*
*.un~
7 changes: 3 additions & 4 deletions djpico/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.conf.urls import patterns, url
from django.conf.urls import url

urlpatterns = patterns(
'',
urlpatterns = [
url(r'pico.js|client.js', 'djpico.views.picojs', name='picojs'),
url(r'^.*$', 'djpico.views.index', name='index'),
)
]
8 changes: 7 additions & 1 deletion djpico/views.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,10 @@
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.conf import settings
from distutils.version import StrictVersion
import django

DJANGO_VERSION = StrictVersion(django.get_version())

pico.server.DEBUG = settings.DEBUG

@@ -16,7 +20,7 @@ def index(request):
path = '/' + request.path.split('/pico/')[-1]
try:
pico_response = pico.server.handle_api_v2(path, params, request)
except PicoError, e:
except PicoError as e:
pico_response = e.response
code, reason = pico_response.status.split(' ', 1)
response = HttpResponse(pico_response.output,
@@ -29,4 +33,6 @@ def index(request):

def picojs(request):
f = open(pico.server.pico_path + 'client.js')
if DJANGO_VERSION >= StrictVersion('1.8'):
return HttpResponse(f.read())
return HttpResponse(f.read(), mimetype='application/javascript')