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. 使用 Vue.js 和 Chart.js 制作绚丽多彩的图表

    本文作者:Jakub Juszczak 编译:胡子大哈 翻译原文:http://huziketang.com/blog/posts/detail?postId=58e5e0e1a58c240ae35b ...

  2. NYOJ--311(完全背包)

    题目:http://acm.nyist.net/JudgeOnline/problem.php?pid=311 分析:这里就是一个完全背包,需要注意的就是初始化和最后的输出情况        dp[j ...

  3. 微信支付URL编解码小方法

    --> 打开chrome --> F12或Fn+F12打开控制台 --> encodeURIComponent("url") --> 回车

  4. elasticsearch river 从数据库中导入数据

    Elasticsearch中使用reiver-jdbc导入数据 2014-05-13 15:10 本站整理 浏览(3384)     Elasticsearch中使用reiver-jdbc导入数据,有 ...

  5. What is python .. (“dot dot”) notation syntax?

    What you have is a float literal without the trailing zero, which you then access the __truediv__met ...

  6. python使用suds来调用webservice

    对于python仅作为客户端调用webservice的情况,推荐使用suds库来完成,比起zsi,soapy之类,它可以说是相当轻量级,使用非常方便. 安装suds建议使用easy_insall来做. ...

  7. BZOJ2191:Splite

    Description 给两个多边形,问否在平移旋转不翻转不重叠的情况下拼成一个凸多边形. Input 每组第一行一个数N表示第一个多边形的顶点数,下接N行按顺序(逆/顺时针)给出顶点坐标,再下一行给 ...

  8. Ubuntn16.04修改pip源

    将python的pip源修改为中科大的镜像 cd ~ touch pip.conf sudo gedit pip.conf 在新打开的文件中写入: [global] trusted-host = py ...

  9. PAT甲级——A1016 Phone Bills

    A long-distance telephone company charges its customers by the following rules: Making a long-distan ...

  10. Redis学习03——存储字符串(String)

    --------------------- 作者:愤怒的小明 来源:CSDN 原文:https://blog.csdn.net/qiwenmingshiwo/article/details/78118 ...