Book Image

Learning Website Development with Django

Book Image

Learning Website Development with Django

Overview of this book

Table of Contents (18 chapters)
Learning Website Development with Django
Credits
About the Author
About the Reviewers
Preface
Index

Creating the Bookmark Submission Form


Now that we can store tag data along with other bookmark information, we are ready to create a form for submitting bookmarks to the database; this form will let users specify the bookmark's URL, title and tags. The process of creating this form is very similar to that of the registration form that we created in the previous chapter. In fact, the method explained here can be used to create any HTML form that saves information into the database.

The first step in building our form is defining a class for it. So open bookmarks/forms.py and add the following class to it:

class BookmarkSaveForm(forms.Form):
  url = forms.URLField(
    label='URL',
    widget=forms.TextInput(attrs={'size': 64})
  )
  title = forms.CharField(
    label='Title',
    widget=forms.TextInput(attrs={'size': 64})
  )
  tags = forms.CharField(
    label='Tags',
    required=False,
    widget=forms.TextInput(attrs={'size': 64})
  )

This code should look familiar to you. For each field...