Debugging Dependencies of Django Project in Eclipse

This is another one of those posts to help myself in the future.  I’ve got some legacy python projects whose directions only get you a django app running in a virtualenv within eclipse but the dependencies themselves are not debuggable.

It was straightforward once I found the right advice.

If you’re like me and have a build that creates a virtualenv with everything installed already by pip and a requirements.txt file.  Here’s how to get the environment and eclipse changed so that you can debug any dependency.

#Step 1.  Remove the dependencies files from the virtualenv

This works for mac and uninstalls files that might have spaces in them too

python install --record files.txt
# inspect files.txt to make sure it looks ok. Then:
tr '\n' '\0' < files.txt | xargs -0 sudo rm -f --

I figured that out after a few different attempts and the best way to do it came from StackOverflow here:


#Step 2. Add the source folder as an external build dependency on the Python Interpreter Path

Add source folder to eclipse for debugging dependency






Credit for this step goes to a small sentence buried here:


That’s it.  Restart your django server and set a breakpoint inside that internal dependency.

This will save you a ton of time vs. all those import pdb; pdb.set_trace() statements


This will break the virtualenv from the command line so for things like python commands.  For those items, I went ahead and set up a second virtualenv.

django show stacktrace

This is a quick one more to save me time than anything else.

If you’re looking for how to get the stacktrace when a django command crashes, the –traceback option is what you’re looking for.

Use it like this:

python <methodname> --traceback

cURL Example: Post a JSON File with Basic Auth

The web was missing a clear example that showed how to POST a JSON file with Basic Auth.  I love using cURL for it’s simplicity when trying out api’s and other services that I might want to use and have spent a decent amount of time figuring this particular usage out more than once.  If nothing else, I’ll be helping myself next time.

cURL JSON + Basic Auth Samples

In this case, I have a file locally that’s contents are the JSON which I want to be the payload of the POST.  Note that I do not want to POST the file as with a multi-part form upload.

curl -X POST -d @pathtofile

Depending on the service you are calling, you might also need to set the Content-Type and encoding.

curl --header "Content-Type: application/json;charset=UTF-8" -X POST -d @pathtofile

Finally, for troubleshooting, I’ve found it useful to either use the verbose -v for inspecting headers or –trace-ascii /dev/stdout for seeing the content of the request

curl -X POST -d @pathtofile -v
curl -X POST -d @pathtofile --trace-ascii /dev/stdout

Sample Output of –trace-ascii /dev/stdout command

== Info: Trying…
== Info: Connected to ( port 443 (#0)
== Info: TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
== Info: Server certificate:
== Info: Server auth using Basic with user ‘admin’
=> Send header, 241 bytes (0xf1)
0000: POST /demo HTTP/1.1
0031: Host:
004f: Authorization: Basic Z3JlZW5oYXRhZG1pbjoxMjNBZG1pbiE=
0086: User-Agent: curl/7.43.0
009f: Accept: */*
00ac: Content-Type: application/json;charset=UTF-8
00da: Content-Length: 596
=> Send data, 596 bytes (0x254)
0000: { “Students”: [{ “MIS_ID”: 201073, “Forename”: “Test”, “Surname
0040: “: “Tester”, “Email”: “”, “YearGroup”: “6
0080: “, “Gender”: “M”, “Password”: “Ab@12” }, { “MIS_ID”: 161201, “Fo
00c0: rename”: “Tester”, “Surname”: “Test”, “Email”: “xyz.abcd@gm
0100:”, “YearGroup”: “6”, “Gender”: “F”, “Password”: “Ab@12
0140: ” }], “Staff”: [{ “TeacherID”: 220380, “Title”: “Mrs”, “Forename
0180: “: “Test”, “Surname”: “Tester”, “Email”: “xyz.abcd@gmail.
01c0: com” }], “Groups”: [{ “GroupID”: 63, “GroupName”: “6A Science”, ”
0200: GroupType”: “Class”, “GroupDescription”: “6A Science”, “PrimaryS
0240: taffId”: 220380 }] }
== Info: upload completely sent off: 596 out of 596 bytes
<= Recv header, 17 bytes (0x11)
0000: HTTP/1.1 200 OK
<= Recv header, 52 bytes (0x34)
0000: Cache-Control: no-cache, no-store, must-revalidate
<= Recv header, 47 bytes (0x2f)
0000: Content-Type: application/json; charset=utf-8
<= Recv header, 37 bytes (0x25)
0000: Date: Wed, 09 Dec 2015 16:02:52 GMT
<= Recv header, 40 bytes (0x28)
0000: Expires: Thu, 19 Jun 1980 19:19:19 GMT
<= Recv header, 18 bytes (0x12)
0000: Pragma: no-cache
<= Recv header, 15 bytes (0xf)
0000: Server: nginx
<= Recv header, 45 bytes (0x2d)
0000: Strict-Transport-Security: max-age=31536000
<= Recv header, 23 bytes (0x17)
0000: Vary: Accept-Encoding
<= Recv header, 20 bytes (0x14)
0000: Content-Length: 25
<= Recv header, 24 bytes (0x18)
0000: Connection: keep-alive
<= Recv header, 2 bytes (0x2)
<= Recv data, 25 bytes (0x19)
0000: {“i”:”4T7hz8tz8KU7ms2rz”}
== Info: Connection #0 to host left intact

Android Phonegap Native Timepicker

So I’ve been working on a simple android app and I finally got audacious and started to move beyond the basics. I was able to get an app in the store with just my HTML/JS/CSS skills pretty easily which makes phonegap a big success.

Anyhow, now my latest fiasco was to try and use the native android timepicker and while I’ve still got a ways to go, I wanted to post my working code that I also put back on a discussion I had with myself on the google group.

FWIW here’s what I’ve got working.

A simple TimePicker class with a showTimePicker method.

public class TimePicker {
private DroidGap mGap;

public TimePicker(DroidGap gap)
mGap = gap;

public void showTimePicker(){

A custom TimePickerDialog.OnTimeSetListener which is initialized with
knowledge of DroidGap too…

public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mGap.sendJavascript(” callback javascript goes here!”);

Initialize and add the createdialog stuff like the android dialog

TimePicker timepicker = new TimePicker(this, appView);
appView.addJavascriptInterface(timepicker, “TimePicker”);

Then in the javascript, once phonegap loads, you can refer to the


Hope that Saves Somebody else some time or inspires somebody to show
me the ways of the plugin framework.


As I get better at this stuff, I might end up understanding how to do it within the plugin architecture but for now that’s it.


Django RadioSelect | CheckboxSelectMultiple | SelectDateWidget Examples

In trying to use django built-in forms, I had the most trouble finding good examples of django radioselect, checkboxselectmultiple and selectdatewidget.

Here’s my attempt to help others looking into using Django RadioSelect, CheckboxSelectMultiple, or the SelectDateWidget.

Django RadioSelect Example

from django.forms.widgets import RadioSelect

RADIO_CHOICES = [['1','Radio 1'],['2','Radio 2']]

class SimpleForm(forms.Form):
radio = forms.ChoiceField( widget=RadioSelect(), choices=RADIO_CHOICES)

Django CheckboxSelectMultiple Example

from django.forms.widgets import CheckboxSelectMultiple

CHECKBOX_CHOICES = (('1','The first choice'),('2','The Second Choice'))

class SimpleForm(forms.Form):
checkboxes = forms.MultipleChoiceField( required=False, widget=CheckboxSelectMultiple(), choices=CHECKBOX_CHOICES)

Django SelectDateWidget Example

from django.forms.extras.widgets import SelectDateWidget

YEAR_CHOICES = ('2016','2015')
class SimpleForm(forms.Form):
date = forms.DateField(widget=SelectDateWidget(None,YEAR_CHOICES) )

Django Docs

Update 1/3/2016: The official documentation on these have improved but is still buried within a huge post. Here is the link to the latest stable docs:

I Love Django Forms

These are all excellent features and the more I use Django, the more I like it. Chalk up Forms as another part of django that blows away any other web framework I’ve worked with.

Mechanize vs. Scrape:

In the process of automating functional tests, I have ran across another python library, mechanize, that looks to be very promising. Perhaps, even more so than

So far it seems that the mechanize platform is more powerful, as it is able to handle complex tasks like managing a gmail inbox( see ).

My take so far is that offers some nice features for validating that a given page has the tags and elements I am looking for. I’m still new to both of these libraries so if anyone out there has experience with both and could help nudge me in the right direction, it would be much appreciated. for functional website testing

This solution is perfect for testing your website’s functional capabilities. supports sessions and cookies so hitting your authenticated resources is cake.

Here’s a quick sample i wrote to test things out:

from scrape import *
s.follow(“Sign in”)
x = s.doc.first(‘form’)
params = x.get_params()
print s.doc

Try it out with your google account. To verify you’re logged in look for the Sign Out link or alternatively look for a GAUSR cookie in s.cookiejar.

Thanks to Ka-Ping himself for clearing up some of my confusion.

My plan is to use this to test the site as if there were no script/styles enabled. Then to layer on browser behavior ( AJAX etc…), I’ll look to Selenium or something of the kind.

Appengine + Django 1.1

So i got past my previous post with a different cell phone number. Now I know getting an appengine account is a more difficult than most online accounts. It makes sense too given free website hosting is at stake.

Anyhow, after a short time i was able to get django 1.1 up and running on appengine. For a little clarity, this provides all the glory of django templates,, middleware, forms, settings. But because of the big table db implementation of appengine, the admin tool, auth, session, and anything else built-in and dependent on django models will not work.

I found some other blogs that were close, but none of the step by steps worked for me. I followed instructions found at goole python libraries – django.

Since i learn best from code, I checked a basic project into github that i’ll continue to update on git as i make updates.

Browse the code on git.

Django Web Framework

So i slammed my old XP machine with Ubuntu this weekend and set to go through the django tutorial.

I’d already had a little experience with django, but hadn’t gone through the basics as another team member had set up our project.

After going through the tutorial,, i am confident that the way django encompasses the business model in its use of, maps urls in, and provides a free admin tool makes it the best “framework” for creating web sites quick and easy. Pair this framework with what is already known to be an easy language, python, and you’ve got a winner.

I’ve yet to use django/python on anything over a month project, so i can’t really comment on whether or not Cal Henderson’s,, statement that if you need to build a “serious” website than the advantages of using a framework like django will at some point come crashing down by the need to modify and adapt the framework for your specific usages.