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

Working with different content types


In Chapter 13, Creating API Views, when we composed and sent POST and PUT commands, we had to use the use the -H "Content-Type: application/json" option to indicate curl to send the data specified after the -d option as application/json. We had to use this option because the default content-type in curl is application/x-www-form-urlencoded.

Now, our RESTful Web Service goes beyond JSON and it can also parse application/x-www-form-urlencoded and multipart/form-data data specified in the POST and PUT requests. Hence, we can compose and send a POST command that sends the data as application/x-www-form-urlencoded.

We will compose and send an HTTP request to create a new toy. In this case, we will use the -f option for HTTP.

This option serializes data items from the command line as form fields and sets the Content-Type header key to the application/x-www-form-urlencoded value. Run the next command:

http -f POST :8000/toys/ name="Ken in Rome" description="Ken...