Skip to content

Commit

Permalink
Fixed #1453 -- Fixed code block indentantion on the Getting started p…
Browse files Browse the repository at this point in the history
…age.

Regression in 6061e98.
  • Loading branch information
jackoconnordev authored and felixxm committed Jan 3, 2024
1 parent 3c40337 commit 69e8325
Showing 1 changed file with 89 additions and 79 deletions.
168 changes: 89 additions & 79 deletions djangoproject/templates/start.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,32 @@ <h2>Object-relational mapper</h2>
<div class="collapsing-content">
<p>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.</p>
<a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='topics/db/models' host 'docs' %}">Read more</a>
{# 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 #}
</div>
</li>
<li>
Expand All @@ -97,26 +103,27 @@ <h2>URLs and views</h2>
<p>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.</p>
<p>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.</p>
<a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='topics/http/urls' host 'docs' %}">Read more</a>
{# 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/<int:band_id>/', 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/<int:band_id>/", 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 #}
</div>
</li>
<li>
Expand All @@ -142,81 +149,86 @@ <h2><a href="{{ band.get_absolute_url }}">{{ band.name }}</a></h2>
{% endfor %}
</ul>
</body>
</html>
{% endverbatim %}
{% endpygment %}
</html>{% endverbatim %}{% endpygment %}
</div>
</li>
<li>
<h2>Forms</h2>
<div class="collapsing-content">
<p>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.</p>
<a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='topics/forms' host 'docs' %}">Read more</a>
{% 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 #}
</div>
</li>
<li>
<h2>Authentication</h2>
<div class="collapsing-content">
<p>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.</p>
<a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='topics/auth' host 'docs' %}">Read more</a>
{# 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 #}
</div>
</li>
<li>
<h2>Admin</h2>
<div class="collapsing-content">
<p>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.</p>
<a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='ref/contrib/admin' host 'docs' %}">Read more</a>
{# 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 #}
</div>
</li>
<li>
<h2>Internationalization</h2>
<div class="collapsing-content">
<p>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.</p>
<a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='topics/i18n' host 'docs' %}">Read more</a>

{# 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 %}
Expand Down Expand Up @@ -244,9 +256,7 @@ <h2><a href="{{ band.get_absolute_url }}">{{ band.name }}</a></h2>
{% endfor %}
</ul>
</body>
</html>
{% endverbatim %}
{% endpygment %}
</html>{% endverbatim %}{% endpygment %}
</div>
</li>
<li>
Expand Down

0 comments on commit 69e8325

Please sign in to comment.