Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the concept of Django framework

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is about what the concept of the Django framework is. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

First, you need to understand the concept of the Django framework:

Django is an open source Web application framework written by Python. The frame mode of MVC is adopted, that is, model M, view V and controller C. The main goal of Django is to make it easy to develop complex, database-driven websites.

The core components of Django framework are: object-relational mapping for creating models, perfect management interface for end-users, first-class URL design, designer-friendly template language, cache system.

Then let's take a look at the version of Django:

The above figure describes the release time of the Django framework version and the python version supported by different versions, etc. You can install different Django versions according to different python versions.

After learning about Django, we can start using Django to create projects.

Create a Django project in pycharm

Before creating the project, we first install Django, install command line pip install django==1.11, followed by a number indicating the specified version number, remember to use two equal to yo ~

Then we need to create a virtual environment for Django and a project directory (Note: create a Django project with PyCharm under Windows, the virtual environment and directory have been created directly, so these two steps can be omitted)

Next, you can create a Django project directly in PyCharm. Select File- > New Project- > Django- > Loaction- > your own project name-> Create, so that the project is created. As shown below, my project name is First_Project.

After creating the project, we create a test.py file for testing in the project, enter a print ("hello") to try, and then run test.py: right-click-> Select the run project name, will the console output a hello?

If you want to run the entire Django project, we can: select Run-- > Run-- > your project name, and the console displays as follows:

In addition, we can also configure the IP and Port of the Django server. Select Run- > click Edit Configurations to configure the port you want in it. (you can choose a number between 1 and 65535, preferably 80, but sometimes using 80 will conflict, then use 8080 or 8081)

Configure the database for the Django project

Configure Django's database in the settings file. The default is to use the sqlite database. Here we don't use sqlite, we use MySQL.

First install the driver mysqlclient:pip install mysqlclient of MySQL, and then modify the database configuration of DATABASES in the settings file, as follows:

DATABASES = {'default': {' ENGINE': 'django.db.backends.mysql',' NAME': 'First_Project',' USER': 'first_project',' PASSWORD': '123456,' HOST': '127.0.0.1,' PORT': 3306,}}

Then we can log in to the mysql database in the command window, enter mysql-uroot-p, and then enter the password to log in to the database, as follows:

As above, we have successfully logged in to the database. Let's use the show databases; command line to check if there is a database we just created. If it already exists, change the name of the database in the settings configuration to avoid overwriting the previous database.

Then directly use the create database First_Project; command line to create our database, and then authorize our user users to use grant all on First_Project. * to 'first_project'@'%' identified by' 123456 destroy. Finally refresh the list flush privileges;,. At this time, the user has successfully created it.

We can use the command: mysql-ufirst_project-p123456 to log in, and then use: show databases; to check whether the database has been created successfully. The results are as follows:

Then we can generate the database tables. We now run makemigrations in Tools- > Run manage.py Task to check for updates to the database tables, and run migrate to update the database tables.

New version of MySQL authorization method new version of mysql, modify authority authentication set global validate_password.policy=0;set global validate_password.length=1; user authorization create user 'new_project'@'%' identified by' 123456 grant all on New_Project.* to 'new_project'@'%'; thank you for reading! This is the end of this article on "what is the concept of Django framework". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report