1

This should be one of the simplest things, but I can't find how to do it in the documentation. I have found how to do it python lib2, but I would like to do it with django to get back a status code, content, etc.

Something like:

response = httpget('http://my-ulr.com')
print response.status_code

1 Answer 1

8

This functionality is not part of Django (since the framework is designed mainly to serve request and not to make them), but Django is just Python - you can use Python's built-in urlib2 library, but I would strongly suggest using the excellent Requests library.

Requests is really fun to work with, and you can't say that about urlib2. You can even say Requests is quite djangish in its simple beauty, and it's creator Kenneth Reitz is an active member of the Django community. But anyways - djangish or not, it works great and you can use it in any Python code.

With Requests your example code would look like this:

import requests

response = requests.get('http://my-ulr.com')
print(response.status_code)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.