zoukankan      html  css  js  c++  java
  • django 登陆

    urlpatterns =( 
    url(r'^admin/', admin.site.urls),
    url(r'^blog/$',view.archive),
    url(r'^articles/',include("news.urls")),
    url(r'^upload/$',newview.upload,name='upload'),
    url(r'^main/$', newview.main),
    url(r'^$', newview.index),
    url(r'^index/$', newview.index),
    )
    
    
    
    
    node2:/django/mysite/news#cat views.py
    # -*- coding: utf-8 -*-
    from __future__ import unicode_literals
    from django.shortcuts import render
    from django.http import HttpResponse
    # Create your views here.
    from django.shortcuts import render,render_to_response,redirect
    from .models import Article
    from django.http import HttpResponse, HttpResponseNotFound
    import datetime
    from django.views.decorators.http import require_http_methods,require_GET
    from django.http import HttpResponseRedirect
    from django.shortcuts import render
    import os
    from django import forms
    from django.forms import fields as Ffields
    from django.forms import widgets as Fwidgets
    from django.forms.extras.widgets import SelectDateWidget
    from django.db import connection,transaction  
    import os
    os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
    def check_user(username,password):
        cursor = connection.cursor()
        cursor.execute("SELECT count(*) FROM news_users WHERE username = %s and password=%s", [username,password])
        row = cursor.fetchone()
        return row[0]
    class UserForm(forms.Form):
        #Username = forms.CharField(max_length=100)
        Username = forms.CharField()
        Password = forms.CharField()
        #comment = forms.CharField(widget=forms.Textarea)
    def main(req):
              username = req.session.get('username',None) 
              print username
              try :
                 req.session['username']
                 return render_to_response('main.html')
              except:
                 try:
                     a=req.POST['username']
                     if (check_user(req.POST['username'],req.POST['password'])== 1):
                        req.session['username']='aa'
                        return render_to_response('main.html')
                     else:
                      response = "用户名或密码错误"
                      return HttpResponse(response)
                      #return redirect('/index/')
                 except:
                   return redirect('/index/')
                 
              
    def index(req):
           try:
             req.session['username']
             return render_to_response('main.html')
           except:
             return render_to_response('index.html')
    
    
    
    登陆页面:
    
    node2:/django/mysite/news#cat templates/index.html
    <html>
    	<head>		
    <title>Index</title>
    		<link rel='stylesheet' type='text/css' href='/static/news/Css/Index/index.css'/>
    	</head>
    	<body>
    		<h1>布丁运维管理平台</h1>
    		<!--图片标签-->
    		<img class="img_bk" src="/static/news/scan.jpg"/>
    		<!--表单提交-->
    		<form action="/main/" method="post" >
    			<table cellspacing="0" cellpadding="0">
    				<tr>
    					<td class="td1">用户名:</td>
    					<td><input type="text" name="username"/></td>
    					<td class="td3"></td>
    					<td class="td4"></td>
    				<tr/>
    				<tr>
    					<td class="td1">密码:</td>
    					<td><input type="password" name="password"/></td>
    					<td class="td3"></td>
    					<td class="td4"></td>
    				<tr/>
    				<!-- <tr> -->
    					<!-- <td class="td1">验证码:</td> -->
    					<!-- <td>   <input type='text' name='code' /></td> -->
    					<!-- <td class="td3"><img src="__APP__/Public/code" οnclick='this.src=this.src+"?"+Math.random()'/></td> -->
    					<!-- <td class="td4"></td> -->
    				<!-- </tr> -->
    				<tr>
    					<td class="td1"></td>
    					<td><input type="submit" value="" name="imgLogin" /></td>
    					<td class="td3"></td>
    					<td class="td4"></td>
    				</tr>
    			</table>
    		</form>
    	</body>
    </html>

  • 相关阅读:
    System path '/Users/hxy/Library/Caches/PyCharm2018.2' is invalid.
    HBase安装指南
    centos6.8下hadoop3.1.1完全分布式安装指南
    PHP服务化搭建之nginx动静分离实战
    Laravel6实现第三方 微信登录
    laravel开发大型电商网站之异常设计思路分析
    Laravel实现大型商城网站之用户注册短信发送项目实战功能开发
    Redis 实现美团的外卖派单系统“附近的人”筛选实战原理分析
    Navicat远程连接MySQL8,必知防坑策略
    laravel大量填充项目测试数据的正确方法
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349400.html
Copyright © 2011-2022 走看看