问题
I use urllib2.urlopen(url)
to get HTML content. The URL is http://127.0.0.1:8000/m.html/
.
This method succeeds in getting the HTML content.
But in Django, if I try to get the HTML content, it stops in the function:
urllib2.urlopen('http://127.0.0.1:8000/m.html/').
It just stops. It does not report an error and the server also stops.
I don't know why it works in a single file, but has problems in Django.
回答1:
The Django development server is single-threaded. It can't both serve the view that's requesting the separate page, and the seperate page itself.
However, I've no idea why you would want to do this anyway - if you want some content from within your application, just call the view code itself.
来源:https://stackoverflow.com/questions/10636608/urllib2-urlopen-fails-in-django