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

边栏推荐
- 【无标题】
- @Autowired的使用
- 016 fundamentals of machine learning mathematics: Introduction
- 51单片机外设篇:电机
- @Feignclient annotated interface. You may not get instances with @autowired
- When crontab scheduled task executes jar through script, it encounters a pit where jar package execution is invalid
- Efcore's solution of multi tenant zero script, table and database read-write separation under SaaS system
- 本周大新闻|FCC曝光Pico 4 VR一体机,雷朋母公司建立智能眼镜实验室
- 【万字长文】使用 LSM-Tree 思想基于.Net 6.0 C# 实现 KV 数据库(案例版)
- 华为设备远程登录(Telnet、SSH)配置
猜你喜欢

Idea2021 failed to start. Could not find main class com/intellij/idea/main
![[dark horse programmer] redis learning notes 002: persistence: RDB and AOF](/img/f2/77adb63718baf42501e5a62059ea0a.png)
[dark horse programmer] redis learning notes 002: persistence: RDB and AOF
![[ten thousand words long text] Based on LSM tree thought Net 6.0 C # realize kV database (case version)](/img/07/235785b7658b5ae022dfa3f53ec86d.png)
[ten thousand words long text] Based on LSM tree thought Net 6.0 C # realize kV database (case version)

Wechat reservation of the completed works of the applet graduation project (6) opening defense ppt

Centernet network structure construction

Visual query (sp_helptext) -- quick query of stored procedures containing specified strings (with source code)

【万字长文】使用 LSM-Tree 思想基于.Net 6.0 C# 实现 KV 数据库(案例版)

How to choose a low code software development platform?

Initial knowledge of WebService (generate jar packages and call methods in remote services)

Wechat applet ordering system graduation design of applet completion works (8) graduation design thesis template
随机推荐
efcore在Saas系统下多租户零脚本分表分库读写分离解决方案
提高代码可续性的小技巧,以connectTo方法为例。
Huawei device remote login (Telnet, SSH) configuration
Wechat reservation of small program completion works (5) assignment book of small program graduation project
FreeMaker模板引擎
Wechat reservation applet graduation project (7) mid term inspection report of applet completion works
Mongodb database
Sina Weibo client (4) - set navigation bar theme
uni-app
Database persistence +jdbc database connection
Wechat reservation of completed works of applet graduation project (4) opening report
Redis/Mysql知识概述
Database query optimization
51单片机内部外设:串口通信
nuscenes数据集3D MOT demo,端到端的目标检测和跟踪,检测跟踪联合框架
Recursive call to print every bit of an integer
OpenGL es to realize the visualization of real-time audio
Foundation 32: page element positioning method XPath --- axis positioning method
Leetcode · 83 biweekly race · 6129. Number of all 0 subarrays · mathematics
[untitled]