summaryrefslogtreecommitdiff
path: root/djangoproject/templates/start.html
blob: 5acc69f1918cb5eb7c4d02dfb81486629a402e1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
{% extends 'base.html' %}
{% load docs i18n %}

{% block layout_class %}full-width{% endblock %}

{% block title %}{% translate "Getting started with Django" %}{% endblock %}

{% block og_title %}{% translate "Getting started with Django" %}{% endblock %}

{% block og_description %}{% translate "It's quick & easy to get up and running with Django" %}{% endblock %}

{% block header %}
  <div class="layout-2col">
    <div class="col two-third">
      <p>{% translate "It’s <em>quick &amp; easy</em> to get up and running with <em>Django</em>." %}</p>
    </div>
    <div class="col one-third last-child">
      <a href="{% url 'download' %}" class="cta">
        {% blocktranslate trimmed %}Download <em>version {{ DJANGO_VERSION }}</em>{% endblocktranslate %}
      </a>
    </div>
  </div>
{% endblock header %}

{% block content %}

  <div class="section">
    <h1>{% translate "Getting started with Django" %}</h1>
    {% url 'document-detail' lang='en' version='stable' url='intro/tutorial01' host 'docs' as tutorial1_url %}
    {% url 'homepage' host 'docs' as docs_homepage_url %}
    <p>
      {% blocktranslate trimmed %}
        Depending how new you are to Django, you can <a href="{{ tutorial1_url }}">try a tutorial</a>, or just
        <a href="{{ docs_homepage_url }}">dive into the documentation</a>.
      {% endblocktranslate %}
    </p>

    <p>
      {% translate "Want to learn more about Django? Read the overview to see whether Django is right for your project." %}
    </p>
    <a class="link-readmore" href="{% url 'overview' %}">{% translate "Django overview" %}</a>
  </div>

  <div class="section">
    <h2>{% translate "Install Django" %}</h2>
    <p>
      {% blocktranslate trimmed %}
        Before you can use Django, you’ll need to install it. Our complete installation guide covers all the
        possibilities; this guide will get you to a simple, minimal installation that’ll work while you walk through
        the introduction.
      {% endblocktranslate %}
    </p>
    <a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='intro/install' host 'docs' %}">
      {% translate "Django installation guide" %}
    </a>
  </div>

  <div class="section">
    <h2>{% translate "Write your first Django app" %}</h2>
    <p>
      {% blocktranslate trimmed %}
        Installed Django already? Good. Now <a href="{{ tutorial1_url }}">try this tutorial</a>, which walks you through
        creating a basic poll application. It’s got two parts:
      {% endblocktranslate %}
    </p>
    <ol>
      <li>{% translate "A public site that lets people view polls and vote in them." %}</li>
      <li>{% translate "An administrative interface that lets you add, change and delete polls." %}</li>
    </ol>
    <a class="link-readmore" href="{{ tutorial1_url }}">{% translate "Take the tutorial" %}</a>
  </div>

  <div class="section">
    <h2>{% translate "Sharpen your skills" %}</h2>
    <p>
      {% blocktranslate trimmed %}
        The official <a href="{{ docs_homepage_url }}">Django documentation</a> covers everything you need to know
        about Django (and then some).
      {% endblocktranslate %}
    </p>
    <a href="{{ docs_homepage_url }}" class="link-readmore">{% translate "Read the docs" %}</a>
  </div>

  <div class="section">
    <h2><span>{% translate "Join the community</span>" %}</h2>
      <p>
        {% url 'community-index' as community_index %}
        {% blocktranslate trimmed %}
          You can help <a href="{{ community_index }}">make us better</a>. Find out about upcoming Django events, learn
          what’s on other Django developers’ minds, find and post jobs, and more.
        {% endblocktranslate %}
      </p>
      <a href="{% url 'community-index' %}" class="link-readmore">{% translate "Join us" %}</a>
    </div>

    <div class="list-collapsing-header">
      <h2><span>{% translate "Intro to Django</span>" %}</h2>
      </div>
      <ul class="list-collapsing">
        <li>
          <h2>{% translate "Object-relational mapper" %}</h2>
          <div class="collapsing-content">
            <p>
              {% blocktranslate trimmed %}
                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.
              {% endblocktranslate %}
            </p>
            <a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='topics/db/models' host 'docs' %}">
              {% translate "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 %}
        {# fmt:on #}
          </div>
        </li>
        <li>
          <h2>{% translate "URLs and views" %}</h2>
          <div class="collapsing-content">
            <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 . 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 %}
        {% pygment 'python' %}
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>
          <h2>{% translate "Templates" %}</h2>
          <div class="collapsing-content">
            <p>
              {% blocktranslate trimmed %}
                Django’s template language is designed to strike a balance between power and ease. It’s designed to feel
                comfortable and easy-to-learn to those used to working with HTML, like designers and front-end developers.
                But it is also flexible and highly extensible, allowing developers to augment the template language as needed.
              {% endblocktranslate %}
            </p>
            <a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='topics/templates' host 'docs' %}">Read more</a>
      {# No need to escape the HTML: pygment takes care of that #}
            {% pygment 'django' %}
{% verbatim %}
<html>
  <head>
    <title>{% translate "Band Listing" %}</title>
  </head>
  <body>
    <h1>{% translate "All Bands" %}</h1>
    <ul>
    {% for band in bands %}
      <li>
        <h2><a href="{{ band.get_absolute_url }}">{{ band.name }}</a></h2>
        {% if band.can_rock %}<p>{% translate "This band can rock!" %}</p>{% endif %}
      </li>
    {% endfor %}
    </ul>
  </body>
</html>{% endverbatim %}{% endpygment %}
          </div>
        </li>
        <li>
          <h2>{% translate "Forms" %}</h2>
          <div class="collapsing-content">
            <p>
              {% blocktranslate trimmed %}
                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.
              {% endblocktranslate %}
            </p>
            <a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='topics/forms' host 'docs' %}">Read more</a>
        {# 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>{% translate "Authentication" %}</h2>
          <div class="collapsing-content">
            <p>
              {% blocktranslate trimmed %}
                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.
              {% endblocktranslate %}
            </p>
            <a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='topics/auth' host 'docs' %}">{% translate "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 %}
        {# fmt:on #}
          </div>
        </li>
        <li>
          <h2>{% translate "Admin" %}</h2>
          <div class="collapsing-content">
            <p>
              {% blocktranslate trimmed %}
                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.
              {% endblocktranslate %}
            </p>
            <a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='ref/contrib/admin' host 'docs' %}">{% translate "Read more" %}</a>
        {# fmt:off #}
        {% pygment 'python' %}
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 %}
        {# fmt:on #}
          </div>
        </li>
        <li>
          <h2>{% translate "Internationalization" %}</h2>
          <div class="collapsing-content">
            <p>
              {% blocktranslate trimmed %}
                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.
              {% endblocktranslate %}
            </p>
            <a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='topics/i18n' host 'docs' %}">{% translate "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 %}
        {# fmt:on #}
      {# No need to escape the HTML: pygment takes care of that #}
            {% pygment 'django' %}
{% verbatim %}
{% load i18n %}
<html>
  <head>
    <title>{% translate "Homepage - Hall of Fame" %}</title>
  </head>
  <body>
    {# Translated in the view: #}
    <h1>{{ message }}</h1>
    <p>
      {% blocktranslate count member_count=bands.count %}
        Here is the only band in the hall of fame:
      {% plural %}
        Here are all the {{ member_count }} bands in the hall of fame:
      {% endblocktranslate %}
    </p>
    <ul>
    {% for band in bands %}
      <li>
        <h2><a href="{{ band.get_absolute_url }}">{{ band.name }}</a></h2>
        {% if band.can_rock %}<p>{% translate 'This band can rock!' %}</p>{% endif %}
      </li>
    {% endfor %}
    </ul>
  </body>
</html>{% endverbatim %}{% endpygment %}
          </div>
        </li>
        <li>
          <h2>{% translate "Security" %}</h2>
          <div class="collapsing-content">
            <p>{% translate "Django provides multiple protections against:" %}</p>
            <ul>
              <li>{% translate "Clickjacking" %}</li>
              <li>{% translate "Cross-site scripting" %}</li>
              <li>{% translate "Cross Site Request Forgery (CSRF)" %}</li>
              <li>{% translate "SQL injection" %}</li>
              <li>{% translate "Remote code execution" %}</li>
            </ul>

            <a class="link-readmore" href="{% url 'document-detail' lang='en' version='stable' url='topics/security' host 'docs' %}">{% translate "Read more" %}</a>

          </div>
        </li>
      </ul>

{% endblock content %}