Book Image

Learn Web Development with Python

By : Fabrizio Romano, Gaston C. Hillar, Arun Ravindran
Book Image

Learn Web Development with Python

By: Fabrizio Romano, Gaston C. Hillar, Arun Ravindran

Overview of this book

If you want to develop complete Python web apps with Django, this Learning Path is for you. It will walk you through Python programming techniques and guide you in implementing them when creating 4 professional Django projects, teaching you how to solve common problems and develop RESTful web services with Django and Python. You will learn how to build a blog application, a social image bookmarking website, an online shop, and an e-learning platform. Learn Web Development with Python will get you started with Python programming techniques, show you how to enhance your applications with AJAX, create RESTful APIs, and set up a production environment for your Django projects. Last but not least, you’ll learn the best practices for creating real-world applications. By the end of this Learning Path, you will have a full understanding of how Django works and how to use it to build web applications from scratch. This Learning Path includes content from the following Packt products: • Learn Python Programming by Fabrizio Romano • Django RESTful Web Services by Gastón C. Hillar • Django Design Patterns and Best Practices by Arun Ravindran
Table of Contents (33 chapters)
Title Page
About Packt
Contributors
Preface
Index

Sending HTTP requests with unsupported HTTP verbs


Now, we will compose and send HTTP requests with an HTTP verb that isn't supported for the toys resource collection. Run the following command:

http PATCH :8000/toys/

The following is the equivalent curl command:

curl -iX PATCH localhost:8000/toys/

The previous command will compose and send the following HTTP request: PATCH http://localhost:8000/toys/. The request will try to run the views.toy_list function, that is, the toy_list function declared within the toys/views.py file. The @api_view decorator we added to this function doesn't include 'PATCH' in the string list with the allowed HTTP verbs. The default behavior when this happens in the APIView class is to return an HTTP 405 Method Not Allowed status code. The following lines show a sample output with the response from the previous request. A JSON content provides a detail key with a string value that indicates the PATCH method is not allowed in the response body:

HTTP/1.0 405 Method Not...