当前位置:网站首页>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

边栏推荐
- Wechat reservation applet graduation design of applet completion works (1) development outline
- This is the worst controller layer code I've ever seen
- Blue and white porcelain used by Charles
- @Autowired注解的实现原理
- Network solutions for Alibaba cloud services
- 51 MCU peripherals: buzzer
- IDEA下依赖冲突解决方法
- 51 MCU internal peripherals: timer and counter
- 哈希表刷题(上)
- QA robot sequencing model
猜你喜欢

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

Wechat sports field reservation of the finished works of the applet graduation project (4) opening report

Wechat applet ordering system graduation design of applet completion works (2) applet function
![[untitled]](/img/81/06fc796dc6c521eb890207b9de69d8.png)
[untitled]

Fundamentals of C language

serialization and deserialization

How can hospitals achieve efficient and low-cost operation and maintenance? Is there any software that can meet it?

The international summit osdi included Taobao system papers for the first time, and end cloud collaborative intelligence was recommended by the keynote speech of the conference

JD cloud and Forrester consulting released a hybrid cloud report that cloud Nativity has become a new engine driving industrial development

Foundation 31: Selenium positioning dynamic ID element
随机推荐
Mogdb 3.0 how to add a standby database in the environment of one active and one standby
@Implementation principle of Autowired annotation
Bigdecimel in words
Redis learning notes
[untitled]
@Use of data annotation (instead of get and set methods in entity classes)
51 MCU internal peripherals: serial port communication
Wechat sports field reservation of the finished works of the applet graduation project (4) opening report
附加:在在下部分区/县(数据表)
提高代码可续性的小技巧,以connectTo方法为例。
FreeMaker模板引擎
Redis学习笔记
@Principle of Autowired annotation
read
QA robot sequencing model
[dark horse programmer] redis learning notes 003: redis transactions
@Differences between requestparam, @pathparam, @pathvariable and other annotations (use of some annotations)
Network solutions for Alibaba cloud services
IP command usage details
C语言基础