1、 Introduction
Django is a web development framework that can make web development work pleasant and efficient. Using Django enables you to build and maintain high-quality Web applications with minimal cost.
Django features
Powerful data function: Has a powerful database operation interface (QuerySet API), and can execute native SQL if necessary.
Comes with a powerful backend: A few lines of simple code will let your website have a powerful backend and manage content easily!
Elegant URL: match the URL with regularity, pass it to the corresponding function, and define it at will, as you want!
Template system: powerful, easy to expand template system, simple design, separate design of code and style, easier to manage.
Note: When the front and back ends are separated, you can also use Django to develop APIs without the template system at all.
Cache system: combined with Memcached, Redis and other cache systems, better performance and faster loading speed.
Internationalization: Fully supports multi-language applications, allowing you to define the characters for translation, and easily translate into languages of different countries.
The following is the architecture diagram of Django:
Django overview:
**url.py: **URL entry, associated with a function (or generic class) in the corresponding views.py, access to the URL corresponds to a function.
**views.py: **Processing the user's request, corresponding from urls.py, by rendering the web page in templates, the displayed content, such as the user name after logging in, and the data requested by the user, can be output to the web page.
**models.py: **Related to database operations, this is used when storing or reading data, of course you don't need to use it when you don't need the database.
**forms.py: **Forms, users enter data on the browser to submit, verify data, and generate input boxes, etc. Of course, you don’t need to use it.
**Templates folder: The function in **views.py renders the Html template in templates to get dynamic content web pages. Of course, cache can be used to improve the speed.
**admin.py: **Backend, you can have a powerful backend with a small amount of code.
**settings.py: **Django settings, configuration files, such as DEBUG switch, location of static files, etc.
2、 Django environment setup
Use pip to install
1 ), install python and pip
To install Python, we must first update the local APT repository. In your terminal window, we will enter the following commands. Please note that the -y
flag answers the "yes" prompt during the upgrade process. If you want to upgrade to stop for each prompt, remove the flag.
sudo apt-get install python3
To verify the successful installation of Python 3, use the python3 command to run a version check:
python3 -V
The resulting output will be similar to:
Now that we have installed Python 3, in order to install the package from PyPi, Python's package repository, we also need the version.
sudo apt-get install -y python3-pip
To verify that pip has been successfully installed, run the following command:
pip3 -V
You can see similar output:
2 ), install Django
There are three ways to install Django. We will use the pip installation method of this tutorial, but we will introduce all available options for reference.
**Option 1: Install Django in virtualenv
. **
This is ideal when you need to isolate the Django version from the global environment of the server.
**Option 2: Install Django from source. **
If you want the latest software or want something newer than what the Ubuntu APT repository provides, you can install it directly from the source. Please note that if you want your software version to be updated, choosing this installation method requires continuous attention and maintenance.
**Option 3: Use pip to install Django globally. **
Our ongoing choice is pip 3 because we will install Django globally.
Using pip to install Django requires a line of commands, as shown below: (I made an error when installing Django here. It is a problem with the official source of pip. Modify it to Douban source:
sudo pip3 install django
If you want to upgrade pip, you can use it (I suggest that the pip version is low and you need to upgrade):
( sudo) pip install --upgrade pip
If an error occurs during the installation process, the prompt is:
It is usually due to the network, and the download of Django is unsuccessful!
Just try a few more times! ! !
Once installed, verify your Django installation by running a version check:
django-admin --version
(Unfinished...)
Reference materials: https://www.cnblogs.com/rainsoul/p/7730390.html
Recommended Posts