This interval is not too fast. Unlike like some other libraries out there, upgrading is not an exhausting treadmill of change. New versions of Django have very few barriers when updating. This is the benefit you get from a mature and stable project. Learn More I hope that explains why you should pick the latest version. Django is "somewhat opinionated", and hence delivers the "best of both worlds". It provides a set of components to handle most web development tasks and one or two preferred ways to use them.
However, Django's decoupled architecture means that you can usually pick and choose from a number of different options, or add support for completely new ones if desired. In a traditional data-driven website, a web application waits for HTTP requests from the web browser or other client. Depending on what is required it may then read or write information from a database or perform other tasks required to satisfy the request.
The application will then return a response to the web browser, often dynamically creating an HTML page for the browser to display by inserting the retrieved data into placeholders in an HTML template.
Django web applications typically group the code that handles each of these steps into separate files:. It has many similarities to the more familiar Model View Controller architecture.
The sections below will give you an idea of what these main parts of a Django app look like we'll go into more detail later on in the course, once we've set up a development environment.
A URL mapper is typically stored in a file named urls. In the example below, the mapper urlpatterns defines a list of mappings between routes specific URL patterns and corresponding view functions. For example: [item1, item2, item3,]. The first argument to both methods is a route pattern that will be matched.
The path method uses angle brackets to define parts of a URL that will be captured and passed through to the view function as named arguments. We'll talk about these in a later article! The second argument is another function that will be called when the pattern is matched. The notation views. In between, they marshal the other resources of the framework to access databases, render templates, etc. The example below shows a minimal view function index , which could have been called by our URL mapper in the previous section.
Like all view functions it receives an HttpRequest object as a parameter request and returns an HttpResponse object. In this case we don't do anything with the request, and our response returns a hard-coded string. We'll show you a request that does something more interesting in a later section. Django web applications manage and query data through Python objects referred to as models. Models define the structure of stored data, including the field types and possibly also their maximum size, default values, selection list options, help text for documentation, label text for forms, etc.
The definition of the model is independent of the underlying database — you can choose one of several as part of your project settings. Once you've chosen what database you want to use, you don't need to talk to it directly at all — you just write your model structure and other code, and Django handles all the "dirty work" of communicating with the database for you.
The code snippet below shows a very simple Django model for a Team object. The Team class is derived from the django class models. It defines the team name and team level as character fields and specifies a maximum number of characters to be stored for each record. The Django model provides a simple query API for searching the associated database. This can match against a number of fields at a time using different criteria e.
The code snippet shows a view function resource handler for displaying all of our U09 teams. This function uses the render function to create the HttpResponse that is sent back to the browser.
Get it using this shell command, which requires Git :. You can also download a gzipped tarball of the development version. This archive is updated every time we commit code. See the installation guide for further instructions. And be sure to sign up for the django-users mailing list , where other Django users and the Django developers themselves all hang out to help each other.
Feature releases A. These releases will contain new features, improvements to existing features, and such. Patch releases A. Each of these options requires a slightly different configuration and setup.
The following subsections explain some of your choices. For the rest of the article, we'll show you how to setup Django on a small number of operating systems, and that setup will be assumed throughout the rest of this module. Note: Other possible installation options are covered in the official Django documentation.
We link to the appropriate documents below. Almost any computer should have the necessary performance to run Django during development. You can use any Python version supported by your target Django release. For Django 3. The Django project recommends and "officially supports" using the newest available supported Python release.
Note: Python 2. We recommend that you select the same database for both production and development although Django abstracts many of the database differences using its Object-Relational Mapper ORM , there are still potential issues that are better to avoid. For this article and most of this module we will be using the SQLite database, which stores its data in a file. It is, however, an excellent choice for applications that are primarily read-only.
Note: Django is configured to use SQLite by default when you start your website project using the standard tools django-admin. It's a great choice when you're getting started because it requires no additional configuration or setup. When you install Python3 you get a single global environment that is shared by all Python3 code.
While you can install whatever Python packages you like in the environment, you can only install one particular version of each package at a time. Note: Python applications installed into the global environment can potentially conflict with each other i. This can be a problem if you want to create new websites using the latest version of Django while still maintaining websites that rely on older versions. This enables multiple different Django environments on a single computer.
The Django developer team itself recommends that you use Python virtual environments! This module assumes that you've installed Django into a virtual environment, and we'll show you how below.
In order to use Django you will have to install Python on your operating system. This section briefly explains how you can check what versions of Python are present, and install new versions as needed, for Ubuntu Linux Ubuntu Linux You can confirm this by running the following command in the bash terminal:.
However, the Python Package Index tool pip3 you'll need to install packages for Python 3 including Django is not available by default. You can install pip3 in the bash terminal using:.
0コメント