{% 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 %}
{% translate "It’s quick & easy to get up and running with Django." %}
{% blocktranslate trimmed %} Depending how new you are to Django, you can try a tutorial, or just dive into the documentation. {% endblocktranslate %}
{% translate "Want to learn more about Django? Read the overview to see whether Django is right for your project." %}
{% translate "Django overview" %}{% 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 %}
{% translate "Django installation guide" %}{% blocktranslate trimmed %} Installed Django already? Good. Now try this tutorial, which walks you through creating a basic poll application. It’s got two parts: {% endblocktranslate %}
{% blocktranslate trimmed %} The official Django documentation covers everything you need to know about Django (and then some). {% endblocktranslate %}
{% translate "Read the docs" %}{% url 'community-index' as community_index %} {% blocktranslate trimmed %} You can help make us better. Find out about upcoming Django events, learn what’s on other Django developers’ minds, find and post jobs, and more. {% endblocktranslate %}
{% translate "Join us" %}{% 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 %}
{% translate "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 %} {# fmt:on #}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 . import views urlpatterns = [ path("bands/", views.band_listing, name="band-list"), path("bands/{% 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 %}
Read more {# No need to escape the HTML: pygment takes care of that #} {% pygment 'django' %} {% verbatim %}{% translate "This band can rock!" %}
{% endif %}{% 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 %}
Read more {# 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 #}{% 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 %}
{% translate "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 %} {# fmt:on #}{% 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 %}
{% translate "Read more" %} {# 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 #}{% 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 %}
{% translate "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 %} {# fmt:on #} {# No need to escape the HTML: pygment takes care of that #} {% pygment 'django' %} {% verbatim %} {% load i18n %}{% 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 %}
{% translate 'This band can rock!' %}
{% endif %}{% translate "Django provides multiple protections against:" %}