当前位置:网站首页>Django4.0 + web + MySQL 5.7 realize simple login operation
Django4.0 + web + MySQL 5.7 realize simple login operation
2022-07-25 08:47:00 【Ding Jiaxiong】
Django
List of articles
- Django
- Django + Web + MySQL5.7 Realize simple login operation
- 1.1 Django + Web + MySQL5.7
- 1.1.1 Create project
- 1.1.2 Create login application (Django Often called App)
- 1.1.3 register App
- 1.1.4 Configuration database
- 1.1.5 Create views and configurations urls
- 1.1.6 Start the service access test
- 1.1.7 Creating models ( Entity class )
- 1.1.8 Write processing logic views.py
- 1.1.9 Start the service , test
Django + Web + MySQL5.7 Realize simple login operation
1.1 Django + Web + MySQL5.7
1.1.1 Create project

1.1.2 Create login application (Django Often called App)
python manage.py startapp login

1.1.3 register App

1.1.4 Configuration database
Be careful :Django Cannot create database , You need to manually create it in advance

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME':'login',
'USER': 'root',
'PASSWORD': '200039',
'HOST': '127.0.0.1',
'PORT': 3306,
}
}

1.1.5 Create views and configurations urls


stay templates New under the directory login.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1> The user login </h1>
<form method="post" action="/login/">
{% csrf_token %}
<input type="text" name="user" placeholder=" user name ">
<input type="password" name="pwd" placeholder=" password ">
<button type="submit" value=" Submit "> Submit </button>
{
{ error_msg }}
</form>
</body>
</html>
1.1.6 Start the service access test

Or execute the command on the command line
python manage.py runserver


1.1.7 Creating models ( Entity class )

To execute a command on the command line
python manage.py makemigrations
python manage.py migrate

view the database

Manually insert a piece of data (ORM It's fine too , But not the focus of this example , ok , This example has no focus )

1.1.8 Write processing logic views.py

def login(request):
if request.method == "GET":
return render(request,"login.html")
username = request.POST.get("user")
password = request.POST.get("pwd")
user = User.objects.get(id = 1)
user_name = user.username
pass_word = user.password
if username == user_name and password == pass_word:
return HttpResponse(" Login successful ")
return render(request,"login.html",{
"error_msg":" Login failed "})
1.1.9 Start the service , test

Click on the submit

Modify the information

Submit

边栏推荐
- read
- Dependency conflict resolution under idea
- Wechat Reservation Reservation of applet completion works applet graduation project (8) graduation project thesis template
- BGP border gateway protocol basic knowledge points
- Wechat reservation of the completed works of the applet graduation project (6) opening defense ppt
- How can hospitals achieve efficient and low-cost operation and maintenance? Is there any software that can meet it?
- NVIDIA可编程推理加速器TensorRT学习笔记(二)——实操
- [dark horse programmer] redis learning notes 005: enterprise level solutions
- 51 MCU peripherals: Motor
- Idea reads configuration files such as validationmessages.properties Chinese garbled
猜你喜欢

QA robot sequencing model

Intel apologized to the winners of Xe HPG treasure hunt game for product delay and announced the appearance of the prize

Wechat sports ground reservation applet graduation design of applet completion works (2) applet function

为什么要使用MQ消息中间件?这几个问题必须拿下!

Wechat applet ordering system graduation design of applet completion works (2) applet function

PHP reports an error: classes\phpexcel\cell php Line(594) Invalid cell coordinate ESIGN1

Wechat applet ordering system graduation design of applet completion works (8) graduation design thesis template

R language error

Use of lambdaquerywrapper, lambdaupdatewrapper, lambdaquerychainwrapper

When crontab scheduled task executes jar through script, it encounters a pit where jar package execution is invalid
随机推荐
Wechat sports ground reservation applet graduation project of applet completion works (1) development outline
Redis learning notes
Apartment repair reporting system (idea, SSM, MySQL)
PHP gets all child nodes under any parent node of the tree structure
BigDecimel转人民币大写
25位撤销博士学位
Mongodb database
C语言实现二叉平衡树
JVM specification Oracle official website
Wechat reservation of small program completion works (5) assignment book of small program graduation project
@Autowired注解的实现原理
@Differences between requestparam, @pathparam, @pathvariable and other annotations (use of some annotations)
Read and write models and organize notes
Idea2021 failed to start. Could not find main class com/intellij/idea/main
Qt|qlabole change line spacing when displaying multiple lines
Initial knowledge of WebService (generate jar packages and call methods in remote services)
Efcore's solution of multi tenant zero script, table and database read-write separation under SaaS system
机器人跳跃问题
NVIDIA programmable reasoning accelerator tensorrt learning notes (II) - practical operation
Rstudio shows that it can't connect to the web page, or it has a new website.