Django 电脑使用管理
Posted 三人行
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django 电脑使用管理相关的知识,希望对你有一定的参考价值。
1. 配置数据库链接
1 import pymysql 2 pymysql.install_as_MySQLdb()
1 DATABASES = { 2 \'default\': { 3 \'ENGINE\': \'django.db.backends.mysql\', 4 \'NAME\': \'computerManage\', 5 \'USER\': \'root\', 6 \'PASSWORD\': \'123\', 7 \'HOST\': \'localhost\', 8 \'PORT\': \'3306\', 9 } 10 }
2. 取消POST提交限制
1 MIDDLEWARE = [ 2 \'django.middleware.security.SecurityMiddleware\', 3 \'django.contrib.sessions.middleware.SessionMiddleware\', 4 \'django.middleware.common.CommonMiddleware\', 5 # \'django.middleware.csrf.CsrfViewMiddleware\', 6 \'django.contrib.auth.middleware.AuthenticationMiddleware\', 7 \'django.contrib.messages.middleware.MessageMiddleware\', 8 \'django.middleware.clickjacking.XFrameOptionsMiddleware\', 9 ]
3. 使用静态页模板
1 TEMPLATES = [ 2 { 3 \'BACKEND\': \'django.template.backends.django.DjangoTemplates\', 4 \'DIRS\': [os.path.join(BASE_DIR, \'templates\')] 5 , 6 \'APP_DIRS\': True,
4. 配置静态文件目录
1 STATIC_URL = \'/static/\' 2 3 STATICFILES_DIRS = ( 4 os.path.join(BASE_DIR, "static"), 5 )
5. 配置路由
1 from django.conf.urls import url,include 2 from django.contrib import admin 3 import web.urls 4 from django.shortcuts import render_to_response 5 6 def index(request): 7 return render_to_response(\'index.html\') 8 9 urlpatterns = [ 10 url(r\'^$\', index), 11 url(r\'^admin/\', admin.site.urls), 12 url(r\'^web/\', include(\'web.urls\')), 13 ]
1 from django.conf.urls import url 2 from web.views import * 3 urlpatterns = [ 4 url(r\'^pcadd/\',pcAdd), 5 url(r\'^pcedit/(?P<id>\\d+)\',pcEdit), 6 url(r\'^pclist/\',pcList), 7 url(r\'^grouplist/\',groupList), 8 url(r\'^groupadd/\',groupAdd), 9 url(r\'^groupManagePcs/\',groupManagePcs), 10 url(r\'^utypelist/\',userTypeList), 11 url(r\'^utypeadd/\',userTypeAdd), 12 url(r\'^userlist/\',userList), 13 url(r\'^useradd/\',userAdd), 14 ]
6. 模板文件
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 6 <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> 7 <title>{% block title %}{% endblock %}</title> 8 <link rel="stylesheet" href="/static/css/bootstrap.min.css"> 9 <script type="text/javascript" src="/static/js/jquery.js"></script> 10 <script type="text/javascript"> 11 $(function () { 12 var curUrl = window.location.pathname; 13 $("#topNav li").each(function(){ 14 if(curUrl.indexOf($(this).attr("nav"))>-1){ 15 $(this).addClass(\'active\'); 16 }else{ 17 $(this).removeClass(\'active\'); 18 } 19 }); 20 }); 21 </script> 22 {% block headjs %}{% endblock %} 23 </head> 24 <body> 25 <div class="container" style="margin-bottom: 5px;"> 26 <ul id="topNav" class="nav nav-tabs" role="tablist" style="background-color: #efefff"> 27 <li role="presentation" nav="index" style=\'font-weight: bold;\'><a href="/">电脑管理系统</a></li> 28 <li role="presentation" nav="/web/pc"><a href="/web/pclist/">电脑管理</a></li> 29 <li role="presentation" nav="/web/group"><a href="/web/grouplist/">用户组管理</a></li> 30 <li role="presentation" nav="/web/utype"><a href="/web/utypelist/">用户类型管理</a></li> 31 <li role="presentation" nav="/web/user"><a href="/web/userlist/">用户管理</a></li> 32 </ul> 33 </div> 34 {% block content %}{% endblock %} 35 </body> 36 </html>
1 {% extends "base.html" %} 2 {% block title %}录入电脑信息{% endblock %} 3 {% block content %} 4 <div class="container"> 5 <form action="{% if id %}/web/pcedit/{{ id }}{% else %}/web/pcadd/{% endif %}" method="post" class="form-horizontal"> 6 <div class="form-group"> 7 <h3 class="col-md-5 text-center">录入电脑信息</h3> 8 </div> 9 <div class="form-group"> 10 <label class="control-label col-md-2">名称:</label> 11 <div class="col-md-3">{{ form.name }}</div> 12 </div> 13 <div class="form-group"> 14 <label class="control-label col-md-2">编号:</label> 15 <div class="col-md-3">{{ form.code }}</div> 16 </div> 17 <div class="form-group"> 18 <label class="control-label col-md-2">IP:</label> 19 <div class="col-md-3">{{ form.ip }}</div> 20 </div> 21 <div class="form-group"> 22 <div class="col-md-6 text-center"> 23 <button type="submit" class="btn btn-default" name="act" value="save">保存</button> 24 {% if id %} 25 <button type="button" class="btn btn-default" onclick="window.close()" style="margin-left: 20px">关闭</button> 26 {% else %} 27 <button type="submit" class="btn btn-default" name="act" value="add" style="margin-left: 20px">添加</button> 28 {% endif %} 29 </div> 30 </div> 31 <div class="col-md-6 text-center{% if err %} has-error{% endif %}{% if success %} has-success{% endif %}"> 32 <label class="control-label">{{ err }}{{ success }}</label> 33 </div> 34 </form> 35 </div> 36 {% endblock %}
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>首页</title> 6 <script type="text/javascript"> 7 window.location.href="/web/pclist/"; 8 </script> 9 </head> 10 <body> 11 12 </body> 13 </html>
1 {% extends "base.html" %} 2 {% block title %}用户添加{% endblock %} 3 {% block headjs %} 4 <script type="text/javascript"> 5 $(function(){ 6 $("input[name=\'groupId\']").bind("click",function(){ 7 var arr_ords, arr_name; 8 $.ajax({ 9 type:\'POST\', 10 url:"/web/groupManagePcs/", 11 async:false, 12 data:{ord:$(this).val()}, 13 success: function(r){ 14 if(r!=""){ 15 var arr_ret = r.split(\'\\1\') 16 var pcords = arr_ret[0]; 17 var pcnames = arr_ret[1]; 18 if(pcords!=""){ 19 arr_ords = pcords.split(","); 20 arr_name = pcnames.split("\\2"); 21 } 22 } 23 } 24 }); 25 26 if($(this).attr("checked")){ 27 for(var i=0;i<arr_ords.length;i++){ 28 if($("#pc_"+arr_ords[i]).size()==0){ 29 $(\'#pcShow\').append(\'<label class="checkbox-inline"><input type="checkbox" name="pcord" id="pc_Django 电脑使用管理django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)(代码片段
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)(代码片段