Book Image

Django By Example

By : Antonio Melé
Book Image

Django By Example

By: Antonio Melé

Overview of this book

<p>Django is a powerful Python web framework designed to develop web applications quickly, from simple prototypes to large-scale projects. Django encourages clean, pragmatic design, and provides developers with a comprehensive set of tools to build scalable web applications.</p> <p>This book will walk you through the creation of four professional Django projects, teaching you how to solve common problems and implement best practices.</p> <p>The book begins by showing you how to build a blog application, before moving on to developing a social image bookmarking website, an online shop and an e-learning platform. You will learn how to build a search engine and implement a user activity stream. Furthermore, you will create a recommendation engine, an e-commerce coupon system and a content management system. The book will also teach you how to enhance your applications with AJAX, create RESTful APIs and setup a production environment for your Django projects.</p> <p>After reading this book, you will have a good understanding of how Django works and how to integrate it with other technologies to build practical, advanced, web applications.</p>
Table of Contents (19 chapters)
Django By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Posting content from other websites


We are going to allow users to bookmark images from external websites. The user will provide the URL of the image, a title, and optional description. Our application will download the image and create a new Image object in the database.

Let's start by building a form to submit new images. Create a new forms.py file inside the images application directory and add the following code to it:

from django import forms
from .models import Image

class ImageCreateForm(forms.ModelForm):
    class Meta:
        model = Image
        fields = ('title', 'url', 'description')
        widgets = {
            'url': forms.HiddenInput,
        }

As you can see, this form is a ModelForm built from the Image model including only the title, url, and description fields. Our users are not going to enter the image URL directly in the form. Instead, they are going to use a JavaScript tool to choose an image from an external site and our form will receive its URL as a parameter...