Django-ems重构
Published in:2020-09-03 |

Django实现用户登陆,注册,以及session会话强制登陆,以及对员工的信息的增加,删除,修改操作,中间件,上传头像,验证码 ,分页显示

模糊查询, 登陆,注册使用 Jquery-Ajax

Django—-ems项目重构

views视图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import os, random, string, uuid
from django.core.paginator import Paginator
from django.db import transaction
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render, redirect
from captcha.image import ImageCaptcha
from emsapp.models import User, Staff
# 登陆页面
def login1(request):
return render(request, 'emsapp/login.html')
# 登陆
def login(request):
if request.method == "GET":
username = request.GET.get("name")
userpwd = request.GET.get("pwd")
else:
username = request.POST.get("name")
userpwd = request.POST.get("pwd")
print(userpwd, username)
res = User.objects.filter(user_name=username, user_pwd=userpwd)
if res:
# 设置session
request.session['login'] = True
# 使用ajax局部更新
return HttpResponse('ok')
return HttpResponse('用户名或密码错误')
# 注册
def regist(request):
return render(request, 'emsapp/regist.html')
# 验证码生成
def getCaptcha(request):
img = ImageCaptcha()
code = random.sample(string.ascii_uppercase + string.ascii_lowercase + string.digits, 4)
# 拼接字符,通过session传递验证码
random_code = ''.join(code)
request.session['code'] = random_code
data = img.generate(random_code)
return HttpResponse(data, 'image/png')
# 注册逻辑
def regist_logic(request):
username = request.POST.get('username')
password = request.POST.get('pwd')
name = request.POST.get('name')
sex = request.POST.get('sex')
code = request.session['code']
captcha = request.POST.get('captcha')
print(captcha, name, username)
try:
with transaction.atomic():
if captcha.lower() == code.lower():
res = User.objects.filter(user_name=username)
if res:
return HttpResponse('user_have')
else:
User.objects.create(user_name=username, user_pwd=password, name=name, sex=sex)
return HttpResponse('ok')
else:
return HttpResponse('error')
except:
print()
# 主页逻辑
def emplist_logic(request):
staff = Staff.objects.all()
# 实现分页
page_number = request.session.get('page_number') # 添加
page_number1 = request.session.get('page_number1') # 修改更新
num = request.GET.get("num", 1)
paginator = Paginator(staff, per_page=3)
if page_number:
num = paginator.num_pages
request.session['page_number'] = False
if page_number1:
num = page_number1
request.session['page_number1'] = False
if int(num) > paginator.num_pages:
num = paginator.num_pages
elif int(num) < 1:
num = 1
page = paginator.page(num)
return render(request, 'emsapp/emplist.html', {"page": page})
# 添加员工
def addEmp(request):
request.session['page_number'] = True
return render(request, 'emsapp/addEmp.html')
# 添加员工逻辑
def addEmp_logic(request):
try:
name = request.POST.get('name')
salary = request.POST.get('salary')
age = request.POST.get('age')
head_pic = request.FILES.get('head_pic')
ext = os.path.splitext(head_pic.name)[1]
pic = str(uuid.uuid4()) + ext
head_pic.name = pic
with transaction.atomic():
Staff.objects.create(name=name, salary=salary, age=age, head_pic=head_pic)
return redirect('emsapp:emplist_logic')
except:
print()
# 删除员工
def delete(request):
try:
number = request.GET.get('num')
request.session['page_number1'] = number
with transaction.atomic():
id = request.GET.get('id')
staff = Staff.objects.get(pk=id)
staff.delete()
return redirect('emsapp:emplist_logic')
except:
print()
# 更新员工
def updateEmp(request):
id = request.GET.get('id')
staff = Staff.objects.get(pk=id)
number = request.GET.get('num')
request.session['page_number1'] = number
return render(request, 'emsapp/updateEmp.html', {"staff": staff})
# 更新员工逻辑
def updareEmp_logic(request):
try:
id = request.GET.get('id')
staff = Staff.objects.get(pk=id)
name = request.POST.get('name')
salary = request.POST.get('salary')
age = request.POST.get('age')
head_pic = request.FILES.get('head_pic')
ext = os.path.splitext(head_pic.name)[1]
pic = str(uuid.uuid4()) + ext
head_pic.name = pic
with transaction.atomic():
staff.name = name
staff.salary = salary
staff.age = age
staff.head_pic = head_pic
staff.save()
return redirect('emsapp:emplist_logic')
except:
print()
# 模糊查询
def query(request):
staff = request.GET.get("s1")
res = Staff.objects.filter(name__icontains=staff)

def mydefault(u):
if isinstance(u, Staff):
return {'name': u.name, 'salary': u.salary, 'age': u.age}

return JsonResponse({'staff': list(res)}, safe=False, json_dumps_params={'default': mydefault})

emplist.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
{% load static %}
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>emplist</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="{% static 'emsapp/css/style.css' %}"/>
<script src="{% static 'emsapp/js/jquery-1.11.1.min.js' %}"></script>
{% block script %}
<script>
$(document).ready(function () {
$("#query").click(function () {
$.ajax({
type: "GET",
url: "{% url 'emsapp:query' %}",
data: "s1=" + $("#s1").val(),
success: function (c) {
console.log(c);
c = c['staff'];
var str = '<tr><td>姓名</td><td>薪水</td><td>年龄</td></tr>';
for (var i = 0; i < c.length; i++) {
str += "<tr>";
str += "<td>";
str += c[i]['name'];
str += "</td>";
str += "<td>";
str += c[i]['salary'];
str += "</td>";
str += "<td>";
str += c[i]['age'];
str += "</td>";
str += "</tr>";
}
$("#t1")[0].innerHTML = str
}
})
})
})
</script>
{% endblock %}

</head>
<body>
<div id="wrap">
<div id="top_content">
<div id="header">
<div id="rightheader">
<p>
2009/11/20
<br/>
</p>
</div>
<div id="topheader">
<h1 id="title">
<a href="#">main</a>
</h1>
</div>
<div id="navigation">
</div>
</div>
{% block content %}
<div id="content">
<p id="whereami">
</p>
<h1>
Welcome!
</h1>

<div>
<input type="text" id="s1">
<input type="button" value="搜索" id="query">
</div>
<table class="table" id="t1">
<tr class="table_header">
<td>
ID
</td>
<td>
Name
</td>
<td>
Salary
</td>
<td>
Age
</td>
<td>
head_pic
</td>
<td>
Operation
</td>
</tr>
{% for i in page.object_list %}
{% if forloop.counter|divisibleby:2 %}
<tr class="row1" style="background-color: #ffffff">
<td>
{{ forloop.counter }}
</td>
<td>
{{ i.name }}
</td>
<td>
{{ i.salary }}
</td>
<td>
{{ i.age }}
</td>
<td>
<img src="{% static i.head_pic.url %}" alt="图片加载失败" height="70px">
</td>
<td>
<a href="{% url "emsapp:delete" %}?id={{ i.id }}&num={{ page.number }}">delete emp</a>&nbsp;
<a href="{% url "emsapp:updateEmp" %}?id={{ i.id }}&num={{ page.number }}">update emp</a>
</td>

</tr>
{% else %}
<tr class="row2" style="background-color: #eeeeee">
<td>
{{ forloop.counter }}
</td>
<td>
{{ i.name }}
</td>
<td>
{{ i.salary }}
</td>
<td>
{{ i.age }}
</td>
<td>
<img src="{% static i.head_pic.url %}" alt="图片加载失败" height="70px">
</td>
<td>
<a href="{% url "emsapp:delete" %}?id={{ i.id }}&num={{ page.number }}">delete emp</a>&nbsp;<a
href="{% url "emsapp:updateEmp" %}?id={{ i.id }}&num={{ page.number }}">update
emp</a>
</td>

</tr>
{% endif %}
{% endfor %}
</table>
{% if page.has_previous %}
<a href="{% url 'emsapp:emplist_logic' %}?num={{ page.previous_page_number }}"> 上一页</a>
{% endif %}

{% for foo in page.paginator.page_range %}
<a href="{% url 'emsapp:emplist_logic' %}?num={{ foo }}">
{% if foo == page.number %}
<span class="a">{{ foo }}</span>
{% else %}
<span class="b">{{ foo }}</span>
{% endif %}
</a>
{% endfor %}
{% if page.has_next %}
<a href="{% url 'emsapp:emplist_logic' %}?num={{ page.next_page_number }}"> 下一页</a>
{% endif %}
{% if not page.paginator.num_pages == page.number %}
<a href="{% url 'emsapp:emplist_logic' %}?num={{ page.paginator.num_pages }}">尾页</a>
{% endif %}

<form action="{% url 'emsapp:emplist_logic' %}" method="get">
输入页号<input type="text" name="num">
<input type="submit" value="跳转">
</form>
<p>
<input type="button" class="button" value="Add Employee"
onclick="location.href='{% url "emsapp:addEmp" %}?num={{ page.paginator.num_pages }}'"/>
</p>
</div>
{% endblock %}
</div>
<div id="footer">
<div id="footer_bg">
ABC@126.com
</div>
</div>
</div>
</body>
</html>

login.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{% extends "emsapp/emplist.html" %}
{% block script %}
<script>
$(document).ready(function () {
$("#sumbit").click(function () {
$.ajax({
type: "POST",
url: "{% url 'emsapp:login' %}",
data: "name=" + $("#name").val() + "&pwd=" + $("#pwd").val() + '&csrfmiddlewaretoken={{ csrf_token }}',
success: function (msg) {
{#console.log(msg);#}
if (msg == 'ok') {
location.href = "{% url 'emsapp:emplist_logic' %}"
} else {
$("#s1")[0].textContent = msg;
console.log($("#s1"));
}
}
})
})
})
</script>
{% endblock %}

{% block content %}
<div id="content">
<p id="whereami">
</p>
<h1>
login
</h1>
<form action="" method="post" enctype="application/x-www-form-urlencoded">
{% csrf_token %}
<table cellpadding="0" cellspacing="0" border="0"
class="form_table">
<tr>
<td valign="middle" align="right">
username:
</td>
<td valign="middle" align="left">
<input type="text" class="inputgri" name="name" id="name"/>
<span id="s1"></span>
</td>
</tr>
<tr>
<td valign="middle" align="right">
password:
</td>
<td valign="middle" align="left">
<input type="password" class="inputgri" name="pwd" id="pwd"/>
</td>
</tr>
</table>
<p>
<input type="button" id="sumbit" class="button" value="Submit &raquo;"/>
<input type="button" value="注册 &raquo;" class="button"
onclick="location.href='{% url 'emsapp:regist' %}'"/>
</p>
</form>
</div>
{% endblock %}

regist.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{% extends "emsapp/emplist.html" %}
{% block script %}
<script>
$(document).ready(function () {
$(function () {
$("#a1").click(function () {
$("#img1")[0].src = "{% url 'emsapp:getCaptcha' %}?" + new Date().getTime();

})
});
$("#submit").click(function () {
console.log('sdfsdf');
$.ajax({
type: "POST",
url: "{% url 'emsapp:regist_logic' %}",
data: "username=" + $("#username").val() + "&name=" + $("#name").val() + "&pwd=" + $("#pwd").val()
+ "&sex=" + $("[name=sex]").val() + "&captcha=" + $("#captcha").val()
+ "&csrfmiddlewaretoken={{ csrf_token }}",
success: function (msg) {
console.log(msg);
if (msg == 'ok') {
location.href = "{% url 'emsapp:login1' %}"
} else if (msg =='user_have') {
$("#s1")[0].textContent = "用户名已存在"
}else {
$("#s1")[0].textContent = "验证码错误"
}
}
})
})
})

</script>
{% endblock %}
{% block content %}
<div id="content">
<p id="whereami">
</p>
<h1>
注册
</h1>
<form>
{% csrf_token %}
<table cellpadding="0" cellspacing="0" border="0"
class="form_table">
<tr>
<td valign="middle" align="right">
用户名:
</td>
<td valign="middle" align="left">
<input type="text" class="inputgri" id="username"/>
</td>
</tr>
<tr>
<td valign="middle" align="right">
真实姓名:
</td>
<td valign="middle" align="left">
<input type="text" class="inputgri" id="name"/>
</td>
</tr>
<tr>
<td valign="middle" align="right">
密码:
</td>
<td valign="middle" align="left">
<input type="password" class="inputgri" id="pwd"/>
</td>
</tr>
<tr>
<td valign="middle" align="right">
性别:
</td>
<td valign="middle" align="left">

<input type="radio" class="inputgri" name="sex" value="m" checked="checked"/>

<input type="radio" class="inputgri" name="sex" value="f"/>
</td>
</tr>

<tr>
<td valign="middle" align="right">
验证码:
<img id="img1" src="{% url 'emsapp:getCaptcha' %}" width="70px"/>
<a href="javascript:void(0)" id="a1">换一张</a>
</td>
<td valign="middle" align="left">
<input type="text" class="inputgri" name="captcha" id="captcha"/>
</td>
</tr>
<tr>
<td><span id="s1"></span></td>
</tr>
</table>
<p>
<input type="button" id="submit" class="button" value="Submit &raquo;"/>
</p>
</form>
</div>
{% endblock %}

updateEmp.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{% extends "emsapp/emplist.html" %}
{% load static %}
{% block content %}
<div id="content">
<p id="whereami">
</p>
<h1>
update Emp info:
</h1>
<form action="{% url "emsapp:updareEmp_logic" %}?id={{ staff.id }}" method="post" enctype="multipart/form-data">
{% csrf_token %}
<table cellpadding="0" cellspacing="0" border="0"
class="form_table">
<tr>
<td valign="middle" align="right">
id:
</td>
<td valign="middle" align="left">
{{ staff.id }}
</td>
</tr>
<tr>
<td valign="middle" align="right">
name:
</td>
<td valign="middle" align="left">
<input type="text" class="inputgri" name="name" value="{{ staff.name }}"/>
</td>
</tr>
<tr>
<td valign="middle" align="right">
salary:
</td>
<td valign="middle" align="left">
<input type="text" class="inputgri" name="salary" value="{{ staff.salary }}"/>
</td>
</tr>
<tr>
<td valign="middle" align="right">
age:
</td>
<td valign="middle" align="left">
<input type="text" class="inputgri" name="age" value="{{ staff.age }}"/>
</td>
</tr>
<tr>
<td valign="middle" align="right">
head_pic:
</td>
<td valign="middle" align="left">
<img src="{% static staff.head_pic.url %}" alt="图片加载失败" height="70px">
<input type="file" name="head_pic">
</td>
</tr>
</table>
<p>
<input type="submit" class="button" value="Confirm"/>
</p>
</form>
</div>
{% endblock %}

addEmp.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{% extends "emsapp/emplist.html" %}
{% block content %}
<div id="content">
<p id="whereami">
</p>
<h1>
add Emp info:
</h1>
<form action="{% url "emsapp:addEmp_logic" %}" method="post" enctype="multipart/form-data">
{% csrf_token %}
<table cellpadding="0" cellspacing="0" border="0"
class="form_table">
<tr>
<td valign="middle" align="right">
name:
</td>
<td valign="middle" align="left">
<input type="text" class="inputgri" name="name" />
</td>
</tr>
<tr>
<td valign="middle" align="right">
salary:
</td>
<td valign="middle" align="left">
<input type="text" class="inputgri" name="salary" />
</td>
</tr>
<tr>
<td valign="middle" align="right">
age:
</td>
<td valign="middle" align="left">
<input type="text" class="inputgri" name="age" />
</td>
</tr>
<tr>
<td valign="middle" align="right">
head_pic:
</td>
<td valign="middle" align="left">
<input type="file" class="inputgri" name="head_pic" />
</td>
</tr>
</table>
<p>
<input type="submit" class="button" value="Confirm" />
</p>
</form>
</div>
{% endblock %}

中间件myMiddleware

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# _*_coding:UTF-8 _*_
from django.shortcuts import render
from django.utils.deprecation import MiddlewareMixin
class MyMiddleware(MiddlewareMixin): # 自定义的中间件
def __init__(self, get_response): # 初始化
super().__init__(get_response)
print("中间件已经初始化完毕")

# view处理请求前执行
def process_request(self, request): # 某一个view
if 'login' not in request.path:
is_login = request.session.get('login')
if is_login:
pass
elif "regist" in request.path:
pass
elif "getCaptcha" in request.path:
pass
else:
return render(request, 'emsapp/login.html')

# 在process_request之后View之前执行
def process_view(self, request, view_func, view_args, view_kwargs):
print("view:", request, view_func, view_args, view_kwargs)

# view执行之后,响应之前执行
def process_response(self, request, response):
print("response:", request, response)
return response # 必须返回response

# 如果View中抛出了异常
def process_exception(self, request, ex): # View中出现异常时执行
print("exception:", request, ex)

urls.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# _*_coding:UTF-8 _*_
from django.urls import path
from emsapp import views

app_name = 'emsapp'
urlpatterns = [
path('login/',views.login, name='login' ),
path('login1/',views.login1, name='login1' ),
path('regist/',views.regist, name='regist' ),
path('addemp/',views.addEmp, name='addEmp' ),
path('updateemp/',views.updateEmp, name='updateEmp' ),
path('delete/',views.delete, name='delete' ),
path('emplist_logic/',views.emplist_logic,name='emplist_logic'),
path('regist_logic/',views.regist_logic,name='regist_logic'),
path('addEmp_logic/',views.addEmp_logic,name='addEmp_logic'),
path('updateEmp_logic/',views.updareEmp_logic,name='updareEmp_logic'),
path('getCaptcha/',views.getCaptcha,name='getCaptcha'),
path('query/',views.query,name='query'),

]

settings.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"""
Django settings for ems project.

Generated by 'django-admin startproject' using Django 2.0.6.

For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/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/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'f+x_dfajz+9lvvmzvz-6q$f!i9+*&6kxjc+@ql9ubm$2ub7au9'

# 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',
'emsapp',
]

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',
#激活中间件
'emsapp.myMiddleware.MyMiddleware',
]

ROOT_URLCONF = 'ems.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 = 'ems.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'test',
'USER': 'root',
'HOST': 'localhost',
'PORT': '3306',
'PASSWORD': '123456'
}
}


# Password validation
# https://docs.djangoproject.com/en/2.0/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/2.0/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/2.0/howto/static-files/

STATIC_URL = '/static/'
# STATIC_ROOT=os.path.join(BASE_DIR,'static') #用于nginx收集静态资源时使用
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
STATICFILES_DIRS = [os.path.join(BASE_DIR,'static'),MEDIA_ROOT]
Prev:
Linux-常用指令
Next:
Django-员工操作