from django.shortcuts import render
# Create your views here. from django.shortcuts import render
from django.shortcuts import redirect #重新定向模块 def login(request):
#包含用户提交的所有信息
#获取用户提交方法
#print(request.method)
error_msg = ""
if request.method == "POST":
#获取用户通过POST提交过来的数据
user =request.POST.get('user',None)
pwd =request.POST.get('pwd',None)
if user == 'root' and pwd == '':
#去跳转到
return redirect('http://www.baidu.com')
else:
#用户密码不匹配
error_msg = '用户名或密码错误'
# user = request.POST['user']
# pwd = request.POST['pwd']
# print(user,pwd)
return render(request,'login.html',{'error_msg':error_msg})

views.py

 """
Django settings for S14Djngo project. Generated by 'django-admin startproject' using Django 1.11.6. For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/ For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
""" import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '^mh@&$v_x+3@+rz$ho$l^t^=tx-=b1a3ylc#nrnuh&mayil-4*' # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
] MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
#'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
] ROOT_URLCONF = 'S14Djngo.urls' TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
] WSGI_APPLICATION = 'S14Djngo.wsgi.application' # Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
} # Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
] # Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/ STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static' ),
)

settings.py

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="/static/commons.css"/>
<style>
label{
width:80px;
text-align:right;
display: inline-block;
}
</style>
</head>
<body> <form action="/login" method="post">
<p>
<label for="username">用户名:</label>
<input id="username" name="user" type='text'/>
</p>
<p>
<label for="password">密码:</label>
<input id="password" name="pwd" type='password'/>
<input type="submit" value="提交"/>
<span style="color:red;">{{ error_msg }}</span>
</p>
</form>
<script src ="/static/jquery.min.js"></script>
</body>
</html>

login.html


其他文件参考以下步骤

用JetBrains PyCharm 2017.2创建运行Django程序
http://www.cnblogs.com/ujq3/p/7882030.html

创建多个Django业务模块
http://www.cnblogs.com/ujq3/p/7884075.html

Django多业务模块的写法
http://www.cnblogs.com/ujq3/p/7884279.html

Django与HTML业务基本结合--基本的用户名密码提交方法2
http://www.cnblogs.com/ujq3/p/7884615.html

Django静态文件以及模板文件的配置
http://www.cnblogs.com/ujq3/p/7884881.html

Django用户名密码错误提示的更多相关文章

  1. vmware vcenter orchestrator configuration提示“用户名密码错误或登录失败超过次数被锁定”

    首次登录,使用默认用户密码登录vmware/vmware vmware vcenter orchestrator configuration提示"用户名密码错误或登录失败超过次数被锁定&qu ...

  2. win7访问局域网总提示用户名密码错误解决方案

    win7访问局域网总提示用户名密码错误解决方案 1.点击开始-在搜索栏输入:secpol.msc(或者直接按下win+r键,输入secpol.msc),打开本地安全策略. 2.找到“安全设置”的“本地 ...

  3. selenium(python)登录时账号密码错误提示语

    selenium(python)登录时账号密码错误提示语的获取 可以用text

  4. ajax异步验证用户名密码,提示路径错误

    使用thinkphp框架异步验证用户名和密码的时候,ajax路径错误可能有多重情况.我遇到的是,我自感路径没问题,且先前使用无错.由于多人合作使用svn,所以在更新代码后,使用firebug显示一直是 ...

  5. django后台密码错误

    如果你忘记了设置Django的Admin密码,那么你可以使用createsuperuser来甚至密码,但是如果你忘记了Admin的密码的话,那么就要用Django shell: 1 python ma ...

  6. Django Forms的错误提示

    1.error_messages={} 首先,在构建form表单时,可以用"error_messages={}"自定义错误信息,例如: # form.py 1 from djang ...

  7. python用户登录,密码错误3次则锁定

    需求: 1.输入用户名密码 2.认证成功后显示欢迎信息 3.输错三次后锁定 实现思路: 1.判断用户是否在黑名单,如果在黑名单提示账号锁定. 2.判断用户是否存在,如果不存在提示账号不存在. 3.判断 ...

  8. php 实现密码错误三次锁定账号10分钟

    /** * 登录 * 1.接收数据 * 2.正则判断接收到的数据是否合理 * 3.根据用户名获取用户数据 * 获取到数据 -> 继续执行 * 没有获取到数据 -> 提示:用户名密码错误 * ...

  9. Ajax登录用户名密码

    <script src="http://code.jquery.com/jquery-latest.js"></script>#引入jQuery#当点击函数 ...

随机推荐

  1. Java-MyBatis-MyBatis3-XML映射文件:缓存

    ylbtech-Java-MyBatis-MyBatis3-XML映射文件:缓存 1.返回顶部 1. 缓存 MyBatis 内置了一个强大的事务性查询缓存机制,它可以非常方便地配置和定制. 为了使它更 ...

  2. PAT甲级——A1074 Reversing Linked List

    Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elem ...

  3. <每日一题>题目6:二分查找

    #二分查找 ''' 1.end问题 2.44对应的end<start 找不到情况 3.返回值递归的情况 4,611,aim太大的情况 ''' l = [2,3,5,10,15,16,18,22, ...

  4. 详解position定位与定位应用

    定位一直是WEB标准应用中的难点,如果理不清楚定位那么可能应实现的效果实现不了,实现了的效果可能会走样.如果理清了定位的原理,那定位会让网页实现的更加完美.     定位的定义:    在CSS中关于 ...

  5. myeclipse中tomcat内存大小的设置

    刚刚安装了myeclipse9.0,又配置了tomcat7.0,想用ssh框架搭个项目试试tomcat7.0,没想到刚启动项目就会报错,在tomcat6.0中就不会有问题,上网查了那些都不起作用,后来 ...

  6. Activiti流程变量

    流程变量在整个工作流中扮演很重要的作用 例如:请假流程中有请假天数.请假原因等一些参数都为流程变量的范围.流程变量的作用域范围是流程实例.也就是说各个流程实例的流程变量是不相互影响的. 添加流程变量 ...

  7. Lucene 评分机制一

    1. 评分公式 1.1 公式介绍 这个公式是Lucene实际计算时使用的公式,是由原型公式推导而来 tf(t in d) 表示某个term的出现频率,定义了term t出现在当前document d的 ...

  8. ssh小知识

    1.查看系统在线用户 [root@testdb ~]# w 14:30:26 up 38 days, 21:22, 3 users, load average: 0.00, 0.01, 0.05USE ...

  9. KOA 学习(一)

    一.安装KOA 用npm下载KOA 就会在koa文件夹下生成 二.输出hello,world 我下载的KOA版本号是2.0.1 const Koa = require('koa'); const ap ...

  10. struts2-环境搭建-访问流程-配置详解-常量配置-类详解

    1 struts2概述 1.1 概念  1.2 struts2使用优势 自动封装参数 参数校验 结果的处理(转发|重定向) 国际化 显示等待页面 表单的防止重复提交 struts2具有更加先进的架构以 ...