标签:template 表单提交 ima 后台 代码 setting ror utf-8 site
此APP非andriodAPP。Django的APP可以理解为一个网站中的一个模块,我们可以将每个模块都单独写成一个APP,这样可以让项目变得相对整洁且更加好维护起来。
django-admin startproject BlogPorject
django-admin startapp application
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登录</title>
</head>
<body>
<form action="/myapp/loginx">
账号:<input type="text" name="account"><br>
密码:<input type="password" name="pwd"><br>
<input type="submit" value="登录">
</form>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>首页</title>
</head>
<body>
This is index page!
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登录失败</title>
</head>
<body>
登录失败!!!
</body>
</html>
from django.shortcuts import render
# Create your views here.
def login(request):
"""进入到登录页面"""
return render(request, ‘./login.html‘)
def loginx(request):
"""点击登录后的逻辑处理"""
account = request.GET[‘account‘]
pwd = request.GET[‘pwd‘]
if account == "desire" and pwd == "123456":
return render(request, ‘./index.html‘)
else:
return render(request, ‘./login_error.html‘)
from django.urls import path
from application import views
urlpatterns = [
path(‘login/‘, views.login),
path(‘loginx/‘, views.loginx)
]
from django.contrib import admin
from django.urls import path, include
from application import urls
urlpatterns = [
path(‘admin/‘, admin.site.urls),
path(‘myapp/‘, include(urls))
]
标签:template 表单提交 ima 后台 代码 setting ror utf-8 site
原文地址:https://www.cnblogs.com/desireyang/p/12643333.html