NameError: name ‘urllib2’ is not defined

I am studying mongoDB with python, I met this problem.

When I tried to open a url by python, I copied some code from internet like following:

and met this error:
NameError: name urllib2 is not defined

Then I found that ‘urllib2’ is a lib for python2 while I use python3

Solution is easy by changing import lib

solving unittest bug of csrf_token in Django

in the Chapter 5 of Book “Test-Driven Web Development with Python” written by Harry J.W. Percival, there is a bug in the part of unit test.

while high version of Django(>1.7) rendering template, it will replace the template tag with a <input type="hidden">, the value is csrf_token.
Continue reading “solving unittest bug of csrf_token in Django”