django删除表重建&修改用户密码&base64加密解密字符串&ps|django删除表重建&修改用户密码&base64加密解密字符串&ps aux参数说明&各种Error例子...

1.django的queryset不支持负索引
AssertionError: Negative indexing is not supported.
2.django向前端JavaScript传递列表:

return render(request, 'home.html', {"mem_data": json.dumps(mem_data)) chartData_mem = {{ mem_data | safe }}; 或者 chartData_mem = JSON.parse('{{ mem_data|safe }}'); 在这里声明变量,变量前不能加var JSON.stringfy()将对象、数组转换成字符串; JSON.parse()将字符串转成json对象.

3.django删除表重建
先到数据库把表删掉:drop table; 注释django中对应的Model; 执行以下命令:python manage.py makemigrations python manage.py migrate --fake 去掉注释重新迁移 python manage.py makemigrations; python manage.py migrate

4.用base64加密解密字符串
vrvlinkroot1234 username1 = base64.encodebytes(b'vrvlink') password1 = base64.encodebytes(b'root1234') username1 b'dnJ2bGluaw==\n' password1 b'cm9vdDEyMzQ=\n' 解密 username = base64.decodebytes(username1.encode()).decode() password = base64.decodebytes(password.encode()).decode()

5.django修改用户密码
python manage.py shell from django.contrib.auth.models import User user=User.objects.get(username='XXX') user.set_password('new_password') user.save() 或者 python manage.py changepassword username

6.ps aux参数说明(以BSD的格式来显示进程)
# ps aux| grep "mail\b" root303260.00.0 2773849656 ?SlSep1818:56 ./mail root314710.00.0 103332864 pts/0S+14:230:00 grep mail\b 显示的项目有:USER,PID,%CPU,%MEM,VSZ,RSS,TTY,STAT,START,TIME,COMMAND USER:进程所有者 PID:用户进程号 %CPU:进程占用的CPU百分比 %MEM:占用内存的百分比 VSZ:该进程使用的虚拟內存量(KB) RSS:该进程占用的固定內存量(KB) STAT:进程的状态 START:该进程被触发启动时间 TIME:该进程实际使用CPU运行的时间 COMMAND:进程启动的命令

7.IndexError:list index out of range的错误原因
第1种可能情况 list[index]index超出范围 第2种可能情况 list是一个空的,没有元素,进行list[0]就会出现该错误 我在统计一个程序tomcat的运行时间-run_time时,对一个空列表用了[0],以后当然要避免

8.在取数据的时候要排序(例如第11行),否则可能有如下警告:
UnorderedObjectListWarning: Pagination may yield inconsistent results with an unordered object_list:

9.CommandError: "http://172.16.8.128:10002"
is not a valid port number or address:port pair.
报这样的错是因为我启动时用的命令错了: python3manage.py runserver http://172.16.8.128:10002 不应该加http://,正确命令: python3manage.py runserver 172.16.8.128:10002

10.json.dump()文件更加美观
json.dump(data,f,ensure_ascii=False,sort_keys=True,indent=4)
11.ValueError、TypeError
ValueError: invalid literal for int() with base 10: '10%' 可以int字符串"10",但不能int"10%"、"1.0"这样的字符串. TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' 意思是:你用int可以去整型字符串或数字,但不能为空.

12.RuntimeError
RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you have APPEND_SLASH set 视图函数给一个函数加上了@require_POST,然后给这个函数发送数据时, url写成了下面这样的格式,然后就报如上错 http://192.168.165.10:8000/show/company_data 正确的写法是:在url后面加上"/"

【django删除表重建&修改用户密码&base64加密解密字符串&ps|django删除表重建&修改用户密码&base64加密解密字符串&ps aux参数说明&各种Error例子...】13.终端显示警告:
[05/Sep/2017 12:24:59] "GET /hello HTTP/1.1" 404 1947
Not Found: /favicon.ico
找一个图片格式为ico,命名成:favicon.ico,拷贝到django下的 ./contrib/admin/static/admin/img/ 终端错误消失问题解决.

14.bit、Byte
bit:电脑记忆体中最小的单位 Byte:字节单位,一般表示存储介质大小的单位,一个B(常用大写的B来表示Byte) 可代表一个字母(A~Z)、数字(0~9)、或符号(,.?!%&+-*/),但中文字需要2个Byte. 1 Byte = 8 bits 1 KB = 1024 Bytes bps:“bits per second”常用于表示数据机及网络通讯的传输速率 Bps:“Byte per second”电脑一般都以Bps显示速度.


转载于:https://www.cnblogs.com/fawaikuangtu123/p/9960244.html

    推荐阅读