Skip to content

Problems in "Intro to Django" example code #2684

Description

@medmunds

There are two problems in the example code shown in the start page "Intro to Django" section:

  1. Forms example shows a contact form with sender and cc_myself fields that would likely be broken or vulnerable to abuse in actual use. This example was adapted from Django's forms docs, which are being updated to avoid suggesting unsafe forms practices (see ticket-37162). Although the start page is just a code fragment, we should probably update it to match.

    Current code:

    class BandContactForm(forms.Form):
        subject = forms.CharField(max_length=100)
        message = forms.TextField()
        sender = forms.EmailField()
        cc_myself = forms.BooleanField(required=False)

    Suggestion: rename the last two fields:

    class BandContactForm(forms.Form):
        subject = forms.CharField(max_length=100)
        message = forms.TextField()
        contact_email = forms.EmailField()
        join_fan_club = forms.BooleanField(required=False)

    (Or @nessita suggests just removing the example from that section.)

  2. Admin example has broken code due to incorrect indentation. (Reported by Cyrilattie in Discord #documentation channel.)

    The last two lines of the example (admin.site.register(...)) need to be outdented to work properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions