From 69e8325f92d402f3ccb91c207d2ae2d7daaca006 Mon Sep 17 00:00:00 2001 From: Jack O'Connor Date: Sun, 17 Dec 2023 00:07:56 +0000 Subject: [PATCH] Fixed #1453 -- Fixed code block indentantion on the Getting started page. Regression in 6061e9876ed149a30798a043d9fbd53762cd6901. --- djangoproject/templates/start.html | 168 +++++++++++++++-------------- 1 file changed, 89 insertions(+), 79 deletions(-) diff --git a/djangoproject/templates/start.html b/djangoproject/templates/start.html index bef8b5db2..6a86fd78f 100644 --- a/djangoproject/templates/start.html +++ b/djangoproject/templates/start.html @@ -69,26 +69,32 @@

Object-relational mapper

Define your data models entirely in Python. You get a rich, dynamic database-access API for free — but you can still write SQL if needed.

Read more + {# fmt:off #} {% pygment 'python' %} - from django.db import models - - class Band(models.Model): - """A model of a rock band.""" - name = models.CharField(max_length=200) - can_rock = models.BooleanField(default=True) - - class Member(models.Model): - """A model of a rock band member.""" - name = models.CharField("Member's name", max_length=200) - instrument = models.CharField(choices=( - ('g', "Guitar"), - ('b', "Bass"), - ('d', "Drums"), - ), - max_length=1 - ) - band = models.ForeignKey("Band") - {% endpygment %} +from django.db import models + + +class Band(models.Model): + """A model of a rock band.""" + + name = models.CharField(max_length=200) + can_rock = models.BooleanField(default=True) + + +class Member(models.Model): + """A model of a rock band member.""" + + name = models.CharField("Member's name", max_length=200) + instrument = models.CharField( + choices=( + ("g", "Guitar"), + ("b", "Bass"), + ("d", "Drums"), + ), + max_length=1, + ) + band = models.ForeignKey("Band"){% endpygment %} + {# fmt:on #}
  • @@ -97,26 +103,27 @@

    URLs and views

    A clean, elegant URL scheme is an important detail in a high-quality web application. Django encourages beautiful URL design and doesn’t put any cruft in URLs, like .php or .asp.

    To design URLs for an application, you create a Python module called a URLconf. Like a table of contents for your app, it contains a simple mapping between URL patterns and your views.

    Read more + {# fmt:off #} {% pygment 'python' %} - from django.urls import path +from django.urls import path - from . import views +from . import views - urlpatterns = [ - path('bands/', views.band_listing, name='band-list'), - path('bands//', views.band_detail, name='band-detail'), - path('bands/search/', views.band_search, name='band-search'), - ] - {% endpygment %} +urlpatterns = [ + path("bands/", views.band_listing, name="band-list"), + path("bands//", views.band_detail, name="band-detail"), + path("bands/search/", views.band_search, name="band-search"), +]{% endpygment %} {% pygment 'python' %} - from django.shortcuts import render - from bands.models import Band - - def band_listing(request): - """A view of all bands.""" - bands = Band.objects.all() - return render(request, 'bands/band_listing.html', {'bands': bands}) - {% endpygment %} +from bands.models import Band +from django.shortcuts import render + + +def band_listing(request): + """A view of all bands.""" + bands = Band.objects.all() + return render(request, "bands/band_listing.html", {"bands": bands}){% endpygment %} + {# fmt:on #}
  • @@ -142,9 +149,7 @@

    {{ band.name }}

    {% endfor %} - -{% endverbatim %} - {% endpygment %} +{% endverbatim %}{% endpygment %}
  • @@ -152,15 +157,17 @@

    Forms

    Django provides a powerful form library that handles rendering forms as HTML, validating user-submitted data, and converting that data to native Python types. Django also provides a way to generate forms from your existing models and use those forms to create and update data.

    Read more - {% pygment 'python'%} - from django import forms - - class BandContactForm(forms.Form): - subject = forms.CharField(max_length=100) - message = forms.CharField() - sender = forms.EmailField() - cc_myself = forms.BooleanField(required=False) - {% endpygment %} + {# fmt:off #} + {% pygment 'python' %} +from django import forms + + +class BandContactForm(forms.Form): + subject = forms.CharField(max_length=100) + message = forms.TextField() + sender = forms.EmailField() + cc_myself = forms.BooleanField(required=False){% endpygment %} + {# fmt:on #}
  • @@ -168,15 +175,17 @@

    Authentication

    Django comes with a full-featured and secure authentication system. It handles user accounts, groups, permissions and cookie-based user sessions. This lets you easily build sites that allow users to create accounts and safely log in/out.

    Read more + {# fmt:off #} {% pygment 'python' %} - from django.contrib.auth.decorators import login_required - from django.shortcuts import render - - @login_required - def my_protected_view(request): - """A view that can only be accessed by logged-in users""" - return render(request, 'protected.html', {'current_user': request.user}) - {% endpygment %} +from django.contrib.auth.decorators import login_required +from django.shortcuts import render + + +@login_required +def my_protected_view(request): + """A view that can only be accessed by logged-in users""" + return render(request, "protected.html", {"current_user": request.user}){% endpygment %} + {# fmt:on #}
  • @@ -184,18 +193,21 @@

    Admin

    One of the most powerful parts of Django is its automatic admin interface. It reads metadata in your models to provide a powerful and production-ready interface that content producers can immediately use to start managing content on your site. It’s easy to set up and provides many hooks for customization.

    Read more + {# fmt:off #} {% pygment 'python' %} - from django.contrib import admin - from bands.models import Band, Member +from bands.models import Band, Member +from django.contrib import admin - class MemberAdmin(admin.ModelAdmin): - """Customize the look of the auto-generated admin for the Member model""" - list_display = ('name', 'instrument') - list_filter = ('band',) - admin.site.register(Band) # Use the default options - admin.site.register(Member, MemberAdmin) # Use the customized options - {% endpygment %} +class MemberAdmin(admin.ModelAdmin): + """Customize the look of the auto-generated admin for the Member model""" + + list_display = ("name", "instrument") + list_filter = ("band",) + + admin.site.register(Band) # Use the default options + admin.site.register(Member, MemberAdmin) # Use the customized options{% endpygment %} + {# fmt:on #}
  • @@ -203,20 +215,20 @@

    Internationalization

    Django offers full support for translating text into different languages, plus locale-specific formatting of dates, times, numbers, and time zones. It lets developers and template authors specify which parts of their apps should be translated or formatted for local languages and cultures, and it uses these hooks to localize web applications for particular users according to their preferences.

    Read more - + {# fmt:off #} {% pygment 'python' %} - from django.shortcuts import render - from django.utils.translation import gettext - - def homepage(request): - """ - Shows the homepage with a welcome message that is translated in the - user's language. - """ - message = gettext('Welcome to our site!') - return render(request, 'homepage.html', {'message': message}) - {% endpygment %} +from django.shortcuts import render +from django.utils.translation import gettext + +def homepage(request): + """ + Shows the homepage with a welcome message that is translated in the + user's language. + """ + message = gettext("Welcome to our site!") + return render(request, "homepage.html", {"message": message}){% endpygment %} + {# fmt:on #} {# No need to escape the HTML: pygment takes care of that #} {% pygment 'django' %} {% verbatim %} @@ -244,9 +256,7 @@

    {{ band.name }}

    {% endfor %} - -{% endverbatim %} - {% endpygment %} +{% endverbatim %}{% endpygment %}