实现环境:

1、System version:rh6.5

2、Python version:2.6.6

3、Django version:1.2.7

创建项目:

1、[root@localhost ~]#django-admin.py startproject mysite

2、[root@localhost mysite]#python manage.py startapp app01

3、[root@localhost mysite]#mkdir templates

4、[root@localhost mysite templates]#tourch login.html && tourch success.html

文件配置:

settings.py

[root@localhost mysite]# cat settings.py

# Django settings for mysite project.

DEBUG = True

TEMPLATE_DEBUG = DEBUG

ADMINS = (

# ('Your Name', 'your_email@domain.com'),

)

MANAGERS = ADMINS

DATABASES = {

'default': {

'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.

'NAME': '',                      # Or path to database file if using sqlite3.

'USER': '',                      # Not used with sqlite3.

'PASSWORD': '',                  # Not used with sqlite3.

'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.

'PORT': '',                      # Set to empty string for default. Not used with sqlite3.

}

}

# Local time zone for this installation. Choices can be found here:

# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name

# although not all choices may be available on all operating systems.

# On Unix systems, a value of None will cause Django to use the same

# timezone as the operating system.

# If running in a Windows environment this must be set to the same as your

# system time zone.

TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:

# http://www.i18nguy.com/unicode/language-identifiers.html

LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not

# to load the internationalization machinery.

USE_I18N = True

# If you set this to False, Django will not format dates, numbers and

# calendars according to the current locale

USE_L10N = True

# Absolute filesystem path to the directory that will hold user-uploaded files.

# Example: "/home/media/media.lawrence.com/"

MEDIA_ROOT = ''

# URL that handles the media served from MEDIA_ROOT. Make sure to use a

# trailing slash if there is a path component (optional in other cases).

# Examples: "http://media.lawrence.com", "http://example.com/media/"

MEDIA_URL = ''

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a

# trailing slash.

# Examples: "http://foo.com/media/", "/media/".

ADMIN_MEDIA_PREFIX = '/media/'

# Make this unique, and don't share it with anybody.

SECRET_KEY = '2+^0fao!r+lv@z=u@=&u=+cl520dij-!w8=t7eh-(0b(^8hb#w'

# List of callables that know how to import templates from various sources.

TEMPLATE_LOADERS = (

'django.template.loaders.filesystem.Loader',

'django.template.loaders.app_directories.Loader',

#     'django.template.loaders.eggs.Loader',

)

MIDDLEWARE_CLASSES = (

'django.middleware.common.CommonMiddleware',

'django.contrib.sessions.middleware.SessionMiddleware',

'django.middleware.csrf.CsrfViewMiddleware',

'django.middleware.csrf.CsrfResponseMiddleware',

'django.contrib.auth.middleware.AuthenticationMiddleware',

'django.contrib.messages.middleware.MessageMiddleware',

)

ROOT_URLCONF = 'mysite.urls'

TEMPLATE_DIRS = (

'/root/mysite/templates'

# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".

# Always use forward slashes, even on Windows.

# Don't forget to use absolute paths, not relative paths.

)

INSTALLED_APPS = (

'django.contrib.auth',

'django.contrib.contenttypes',

'django.contrib.sessions',

'django.contrib.sites',

'django.contrib.messages',

'app01'

# Uncomment the next line to enable the admin:

# 'django.contrib.admin',

# Uncomment the next line to enable admin documentation:

# 'django.contrib.admindocs',

)

[root@localhost mysite]#

models.py

urls.py

[root@localhost mysite]# cat urls.py

from django.conf.urls.defaults import *

from app01 import views

# Uncomment the next two lines to enable the admin:

# from django.contrib import admin

# admin.autodiscover()

urlpatterns = patterns('',

# Example:

# (r'^mysite/', include('mysite.foo.urls')),

# Uncomment the admin/doc line below to enable admin documentation:

# (r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:

# (r'^admin/', include(admin.site.urls)),

(r'^$',views.index),

(r'^login/$',views.login),

)

[root@localhost mysite]#

views.py

[root@localhost app01]# cat views.py

# Create your views here.

# -*- coding:utf8 -*-

from django.shortcuts import render_to_response

from django.http import HttpResponse

from django.template import RequestContext

def index(request):

return render_to_response('index.html')

def login(request):

count = 0

user_list = {'gsw1':'111','gsw2':'222','gsw3':'333'}

username = request.GET['username']

password = request.GET['password']

if user_list.has_key(username):

pass

else:

alert = username + ' is not exist.'

return render_to_response('index.html',{'alert':alert})

if username in lock:

alert = "Your account is locked,please contact administrator."

return render_to_response('index.html',{'alert':alert})

else:

while count < 3:

if user_list[username] == password:

#alert = 'Welcome ' + username

return render_to_response('success.html')

else:

alert = 'Password Error'

count += 1

return render_to_response('index.html',{'alert':alert})

else:

lock.append(username)

return render_to_response('index.html'})

[root@localhost app01]#

index.html

[root@localhost templates]# cat index.html

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Title</title>

</head>

<body>

<a href="http://127.0.0.1:8000">index</a>

<form method="get" action="/login/">

Username:<input type="text" name="username"><br>

Password:<input type="password" name="password"><br>

<input type="submit" value="Login">

</form>

` alert `

` count `

</body>

</html>

[root@localhost templates]#

success.html

[root@localhost templates]# cat success.html

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Title</title>

</head>

<body>

<a href='http://127.0.0.1:8000'>index</a>

Welcome

</body>

</html>

[root@localhost templates]#


本文转自 gswljy 51CTO博客,原文链接:http://blog.51cto.com/guoshiwei/1900933


Django 实现WEB登陆(第二版)相关推荐

  1. 智能Web算法第二版前言和译者序

    人工智能和机器学习技术近年来得到了飞速的发展,并成为计算机界乃至全社会炙手可热的话题.这些优秀技术让每个人的生活越来越方便和智能,这让从业者们都感到非常欣喜.在众多有关机器学习和数据挖掘的书籍里,&l ...

  2. Kali Linux Web渗透测试手册(第二版) - 1.3 - 靶机的安装

    Kali Linux Web渗透测试手册(第二版) - 1.3 - 靶机的安装  一.配置KALI Linux和渗透测试环境 在这一章,我们将覆盖以下内容: 在Windows和Linux上安装Virt ...

  3. 黑帽python第二版(Black Hat Python 2nd Edition)读书笔记 之 第五章 WEB黑客(3)暴力破解目录与文件位置

    黑帽python第二版(Black Hat Python 2nd Edition)读书笔记 之 第五章 WEB黑客(3)暴力破解目录与文件位置 文章目录 黑帽python第二版(Black Hat P ...

  4. 黑帽python第二版(Black Hat Python 2nd Edition)读书笔记 之 第五章 WEB黑客(4)暴力破解HTML表单身份验证

    黑帽python第二版(Black Hat Python 2nd Edition)读书笔记 之 第五章 WEB黑客(4)暴力破解HTML表单身份验证 文章目录 黑帽python第二版(Black Ha ...

  5. 【HoorayOS】开源的Web桌面应用框架(第二版 v120311)

    经过大量自愿者的BUG提交,建议讨论之后,迎来了第二版.让我们一起来看看第二版更新了哪些新功能吧. 应用码头 图标右键菜单 桌面右键菜单 主题模块 更多细节上的修改就不一一描述了,以下是测试地址,由于 ...

  6. xiuno4.0 火车头发布模块一Web登陆版

    xiuno4.0 后台无修改版,需登陆,火车头发布模块. 原贴地址:http://blog.62.la/xiuno4-0-%E7%81%AB%E8%BD%A6%E5%A4%B4%E5%8F%91%E5 ...

  7. Web前端开发技术第二版课后上机题(第四章)

    前端开发技术第二版第四章课后上机题答案,代码加图. 代码: <!DOCTYPE html> <html lang="en"> <head>< ...

  8. python核心编程第二版pdf_Python Book电子书pdf版合集 Python核心高级编程第二版

    1小时学会Python.doc 51CTO下载-[Python系列].BeginningPythonFromNovicetoProfessionalSecondEdition.pdf 8.Python ...

  9. 整理对应_JSP第二版课后习题答案【侵权联系我删除】

    JSP第二版课后习题下载:https://download.csdn.net/download/weixin_42859280/11265785 JSP第二版课后习题答案下载:https://down ...

最新文章

  1. 基于 gulp 的 fancybox 源码压缩
  2. inet_ntoa()返回字符串的生命周期
  3. 关于python语言和人工智能哪个说法不正确_在 Windows 7 操作系统中,下列说法错误的是( )。_计算机文化基础答案_学小易找答案...
  4. .NET Compact Framework下的单元测试
  5. Asp.Net Core 已支持 gRPC-Web !!
  6. python数据的格式输出_Python格式化输出
  7. 从MapX到MapXtreme2004[4]-标注AutoLabel
  8. 一个简单计算器demo 拥有记忆和记忆清除功能
  9. SQLite 3 中的数据类型
  10. 《移动通信》学习总结
  11. caffe 中solver.prototxt
  12. 物联网中大数据的挑战有哪些
  13. 数字图像处理 采样定理_数字图像处理(第4版)
  14. DoIP(二)——报文类型
  15. 学校源码php,闪灵CMS学校建站系统(含小程序) v5.0 bulid20200319_php免费源码
  16. 小米wifi驱动 linux驱动,小米wifi驱动程序
  17. C++:tuple的解包tie【tuple<std::string, int, int> tp;tie(name, ages, areaCode) = tp】
  18. foreign key() references 字段名(字段名)详细用法
  19. 7-1 统计字符串中不同种类的字符个数 (10 分)
  20. python情感分析(真实案例完整流程)

热门文章

  1. 借贷记账法下的账户对应关系_事业单位改用的借贷记账法
  2. python词频统计_python统计词频的三种方法
  3. Drupal 网站漏洞修复以及网站安全防护加固方法
  4. Confluence 6 重要缓存和监控
  5. spring boot2 整合(一)Mybatis (特别完整!)
  6. [转]ubuntu linux下DNS重启后丢失(不是Network-manager造成的情况)
  7. 一个很简单的H5的转盘抽奖的(主要用的是css3的属性)
  8. 微信JS-SDK开发:扫一扫接口功能实现
  9. 基于html5制作3D拳击游戏源码下载
  10. 用户名 不在 sudoers文件中,此事将被报告