django



Pdf көрінісі
Дата07.02.2020
өлшемі6,62 Mb.
#57399
Байланысты:
django
24.09.19. 2019 Этнопед.Sillabus-2, Жанерке, Документ (10), Документ (10), ВЛИЯНИЕ ВНЕШНЕГО ДОЛГА НА ЭКОНОМИЧЕСКИЙ РОСТ, тарих, Khusht, Курс аннотациясы, kojaweva diff geomet jatt, lie-lecture8-10, demina, Псху 1, CrystalStructureAnalysis, етб-1120-2 лекция (3)

Django Documentation
Release 2.2.9.dev20191211090926
Django Software Foundation
December 11, 2019

Contents
1
Django documentation
1
1.1
Getting help
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
1.2
How the documentation is organized
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
1.3
First steps
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
1.4
The model layer
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
1.5
The view layer
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
1.6
The template layer
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
1.7
Forms
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
1.8
The development process
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
1.9
The admin
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
1.10 Security
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
1.11 Internationalization and localization
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
1.12 Performance and optimization
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
1.13 Geographic framework
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
1.14 Common Web application tools
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
1.15 Other core functionalities
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
1.16 The Django open-source project
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5
2
Getting started
7
2.1
Django at a glance
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
2.2
Quick install guide
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12
2.3
Writing your first Django app, part 1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13
2.4
Writing your first Django app, part 2
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
19
2.5
Writing your first Django app, part 3
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
31
2.6
Writing your first Django app, part 4
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
37
2.7
Writing your first Django app, part 5
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
42
2.8
Writing your first Django app, part 6
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
52
2.9
Writing your first Django app, part 7
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
54
2.10 Advanced tutorial: How to write reusable apps
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
64
2.11 What to read next
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
69
2.12 Writing your first patch for Django
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
72
3
Using Django
81
3.1
How to install Django
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
81
3.2
Models and databases
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
84
3.3
Handling HTTP requests
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
3.4
Working with forms
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
i

3.5
Templates
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
3.6
Class-based views
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
3.7
Migrations
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
3.8
Managing files
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
3.9
Testing in Django
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
3.10 User authentication in Django
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
3.11 Django’s cache framework
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
3.12 Conditional View Processing
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
3.13 Cryptographic signing
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
3.14 Sending email
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444
3.15 Internationalization and localization
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
3.16 Logging
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
3.17 Pagination
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509
3.18 Security in Django
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513
3.19 Performance and optimization
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517
3.20 Serializing Django objects
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
3.21 Django settings
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
3.22 Signals
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536
3.23 System check framework
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
3.24 External packages
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
4
“How-to” guides
545
4.1
Authentication using REMOTE_USER
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545
4.2
Writing custom django-admin commands
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547
4.3
Writing custom model fields
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
4.4
Custom Lookups
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 562
4.5
Custom template tags and filters
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567
4.6
Writing a custom storage system
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584
4.7
Deploying Django
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585
4.8
Upgrading Django to a newer version
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603
4.9
Providing initial data for models
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604
4.10 Django on Jython
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606
4.11 Integrating Django with a legacy database
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606
4.12 Outputting CSV with Django
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607
4.13 Outputting PDFs with Django
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609
4.14 Overriding templates
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611
4.15 Managing static files (e.g. images, JavaScript, CSS)
. . . . . . . . . . . . . . . . . . . . . . . . . . 612
4.16 How to install Django on Windows
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615
4.17 Writing database migrations
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
5
Django FAQ
623
5.1
FAQ: General
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
5.2
FAQ: Installation
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626
5.3
FAQ: Using Django
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 627
5.4
FAQ: Getting Help
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628
5.5
FAQ: Databases and models
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629
5.6
FAQ: The admin
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
5.7
FAQ: Contributing code
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632
5.8
Troubleshooting
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
6
API Reference
635
6.1
Applications
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 635
6.2
System check framework
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 641
6.3
Built-in class-based views API
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653
ii

6.4
Clickjacking Protection
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 703
6.5
contrib
packages
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 705
6.6
Cross Site Request Forgery protection
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 978
6.7
Databases
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 986
6.8
django-admin
and manage.py
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 999
6.9
Running management commands from your code
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 1025
6.10 Django Exceptions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1026
6.11 File handling
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1030
6.12 Forms
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1037
6.13 Middleware
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1100
6.14 Migration Operations
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1106
6.15 Models
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1114
6.16 Request and response objects
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1273
6.17 SchemaEditor
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1288
6.18 Settings
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1291
6.19 Signals
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1339
6.20 Templates
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1347
6.21 TemplateResponse and SimpleTemplateResponse
. . . . . . . . . . . . . . . . . . . . . 1411
6.22 Unicode data
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1415
6.23 django.urls utility functions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1420
6.24 django.urls functions for use in URLconfs
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1423
6.25 django.conf.urls functions for use in URLconfs
. . . . . . . . . . . . . . . . . . . . . . . . . 1424
6.26 Django Utils
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1425
6.27 Validators
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1440
6.28 Built-in Views
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1444
7
Meta-documentation and miscellany
1447
7.1
API stability
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1447
7.2
Design philosophies
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1448
7.3
Third-party distributions of Django
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1453
8
Glossary
1455
9
Release notes
1457
9.1
Final releases
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1457
9.2
Security releases
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1789
10 Django internals
1809
10.1 Contributing to Django
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1809
10.2 Mailing lists
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1855
10.3 Organization of the Django Project
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1857
10.4 Django’s security policies
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1859
10.5 Django’s release process
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1862
10.6 Django Deprecation Timeline
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1865
10.7 The Django source code repository
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1879
10.8 How is Django Formed?
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1882
11 Indices, glossary and tables
1889
Python Module Index
1891
Index
1893
iii

iv

CHAPTER
1
Django documentation
Everything you need to know about Django.
1.1 Getting help
Having trouble? We’d like to help!
• Try the
FAQ
– it’s got answers to many common questions.
• Looking for specific information? Try the genindex, modindex or the
detailed table of contents
.
• Search for information in the archives of the
django-users
mailing list, or
post a question
.
• Ask a question in the
#django IRC channel
.
• Report bugs with Django in our
ticket tracker
.
1.2 How the documentation is organized
Django has a lot of documentation. A high-level overview of how it’s organized will help you know where to look for
certain things:

Tutorials
take you by the hand through a series of steps to create a Web application. Start here if you’re new to
Django or Web application development. Also look at the “
First steps
” below.

Topic guides
discuss key topics and concepts at a fairly high level and provide useful background information
and explanation.

Reference guides
contain technical reference for APIs and other aspects of Django’s machinery. They describe
how it works and how to use it but assume that you have a basic understanding of key concepts.

How-to guides
are recipes. They guide you through the steps involved in addressing key problems and use-cases.
They are more advanced than tutorials and assume some knowledge of how Django works.
1

Django Documentation, Release 2.2.9.dev20191211090926
1.3 First steps
Are you new to Django or to programming? This is the place to start!
• From scratch:
Overview
|
Installation
• Tutorial:
Part 1: Requests and responses
|
Part 2: Models and the admin site
|
Part 3: Views and templates
|
Part 4: Forms and generic views
|
Part 5: Testing
|
Part 6: Static files
|
Part 7: Customizing the admin site
• Advanced Tutorials:
How to write reusable apps
|
Writing your first patch for Django
1.4 The model layer
Django provides an abstraction layer (the “models”) for structuring and manipulating the data of your Web application.
Learn more about it below:
• Models:
Introduction to models
|
Field types
|
Indexes
|
Meta options
|
Model class
• QuerySets:
Making queries
|
QuerySet method reference
|
Lookup expressions
• Model instances:
Instance methods
|
Accessing related objects
• Migrations:
Introduction to Migrations
|
Operations reference
|
SchemaEditor
|
Writing migrations
• Advanced:
Managers
|
Raw SQL
|
Transactions
|
Aggregation
|
Search
|
Custom fields
|
Multiple databases
|
Custom lookups
|
Query Expressions
|
Conditional Expressions
|
Database Functions
• Other:
Supported databases
|
Legacy databases
|
Providing initial data
|
Optimize database access
|
PostgreSQL
specific features
1.5 The view layer
Django has the concept of “views” to encapsulate the logic responsible for processing a user’s request and for returning
the response. Find all you need to know about views via the links below:
• The basics:
URLconfs
|
View functions
|
Shortcuts
|
Decorators
• Reference:
Built-in Views
|
Request/response objects
|
TemplateResponse objects
• File uploads:
Overview
|
File objects
|
Storage API
|
Managing files
|
Custom storage
• Class-based views:
Overview
|
Built-in display views
|
Built-in editing views
|
Using mixins
|
API reference
|
Flattened index
• Advanced:
Generating CSV
|
Generating PDF
• Middleware:
Overview
|
Built-in middleware classes
1.6 The template layer
The template layer provides a designer-friendly syntax for rendering the information to be presented to the user. Learn
how this syntax can be used by designers and how it can be extended by programmers:
• The basics:
Overview
• For designers:
Language overview
|
Built-in tags and filters
|
Humanization
2
Chapter 1. Django documentation

Django Documentation, Release 2.2.9.dev20191211090926
• For programmers:
Template API
|
Custom tags and filters
1.7 Forms
Django provides a rich framework to facilitate the creation of forms and the manipulation of form data.
• The basics:
Overview
|
Form API
|
Built-in fields
|
Built-in widgets
• Advanced:
Forms for models
|
Integrating media
|
Formsets
|
Customizing validation
1.8 The development process
Learn about the various components and tools to help you in the development and testing of Django applications:
• Settings:
Overview
|
Full list of settings
• Applications:
Overview
• Exceptions:
Overview
• django-admin and manage.py:
Overview
|
Adding custom commands
• Testing:
Introduction
|
Writing and running tests
|
Included testing tools
|
Advanced topics
• Deployment:
Overview
|
WSGI servers
|
Deploying static files
|
Tracking code errors by email
|
Deployment
checklist
1.9 The admin
Find all you need to know about the automated admin interface, one of Django’s most popular features:

Admin site

Admin actions

Admin documentation generator
1.10 Security
Security is a topic of paramount importance in the development of Web applications and Django provides multiple
protection tools and mechanisms:

Security overview

Disclosed security issues in Django

Clickjacking protection

Cross Site Request Forgery protection

Cryptographic signing

Security Middleware
1.7. Forms
3

Django Documentation, Release 2.2.9.dev20191211090926
1.11 Internationalization and localization
Django offers a robust internationalization and localization framework to assist you in the development of applications
for multiple languages and world regions:

Overview
|
Internationalization
|
Localization
|
Localized Web UI formatting and form input

Time zones
1.12 Performance and optimization
There are a variety of techniques and tools that can help get your code running more efficiently - faster, and using
fewer system resources.

Performance and optimization overview
1.13 Geographic framework
GeoDjango
intends to be a world-class geographic Web framework. Its goal is to make it as easy as possible to build
GIS Web applications and harness the power of spatially enabled data.


Достарыңызбен бөлісу:




©engime.org 2024
әкімшілігінің қараңыз

    Басты бет