return HttpResponseRedirect('/index/')# 重定向
返回url格式:http://127.0.0.1:8000/index/会去掉前期的所有路由重新写入/index/'路由 urls代码
from django.urls import path
from django.contrib import admin
from ProductOutWarehouse import views urlpatterns = [
path('admin/', admin.site.urls),
path(r'',views.login),
path(r'login/',views.login),
path(r'login_action/',views.login_action),
path(r'index/',views.index),
] views代码
import os
from django.shortcuts import render,render_to_response,redirect,HttpResponseRedirect
from .models import User # Create your views here. #首页
def login(request):
return render(request,'login.html') def login_action(request):
if request.POST:
acount = (request.POST.get("Acount").strip())
password = (request.POST.get("Password").strip())
user = User.objects.filter(workNumber=acount,password=password)
if user:
print("账户密码正确")
return HttpResponseRedirect('/index/')# 重定向
else:
print("密码错误")
return render(request,"login.html",{"error":"账户不存在"})
return render(request,"login.html")
def index(request):
return render(request,'index.html')
表单代码
<form method="post" action="/login_action/">
{% csrf_token %}
<div class="form-group">
<h3 class="text-left" >帐号</h3>
<input type="text" class="form-control" name="Acount" placeholder="帐号">
</div>
<div class="form-group">
<h3 class="text-left" >密码</h3>
<input type="password" class="form-control" name="Password" placeholder="密码">
</div>
<div class="form-group text-left">
<div class="checkbox checkbox-primary">
<label><input type="checkbox">
<i></i></label>
<span class="white f-s-16 m-l-5">记住密码</span>
</div> <div class="text">
{{ error }}
</div>
</div>
<button type="submit" class="btn btn-block btn-lg btn-primary">登录</button>
</form> form表单传递路由
<form method="post" action="/login_action/">
URL表现为http://127.0.0.1:8000/login_action/

最新文章

  1. MySQL学习笔记十二:数据备份与恢复
  2. Cookbook of QUnit
  3. x01.os.12: 在 windows 中写 OS
  4. 【原】iOS多线程之异步任务+并行队列情况与异步任务+串行队列(主队列)情况
  5. 这个代码怎么改??Help快速排序 quicksort
  6. Ajax请求ashx一般处理程序实现文件下载
  7. 【转载】【挖掘Treap的潜力】
  8. 2013 Esri全球用户大会之元数据支持
  9. 说说SACC2016第八届架构师大会
  10. 基于am3358的lcd输出
  11. statsd.go
  12. 【spring实战第五版遇到的坑】第14章spring.cloud.config.uri和token配置项无效
  13. listener介绍
  14. nginx学习笔记(二)
  15. 每天一个linux命令:chgrp
  16. HTML5游戏 看你有多“色” 开发
  17. 一款easyUI写的界面例子,小记
  18. 安装配置heapster(包含influxdb,grafana)
  19. 【python 3.6】python获取当前时间及过去或将来的指定时间
  20. Single Number and Single Number II

热门文章

  1. socket的阻塞与非阻塞,同步与异步
  2. 基于openssl搭建https服务器
  3. Linux软件包管理之yum在线管理
  4. mysql滑动聚合
  5. #21 Python异常
  6. JVM(二)—— 垃圾回收
  7. 第一册:lesson forty
  8. c# 大批量用户访问数据库报错
  9. Hibernate入门(一)
  10. JVM虚拟机深入理解+GC回收+类加载