index
int64 | repo_name
string | branch_name
string | path
string | content
string | import_graph
string |
|---|---|---|---|---|---|
19,702
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-22/Like/views.py
|
from django.shortcuts import render, HttpResponseRedirect
from django.contrib.contenttypes.models import ContentType
from django.http import JsonResponse
from .models import LikeCount, LikeRecord
# Create your views here.
# 数据操作成功返回数据方法
def success_response(like_num):
data = {}
data['status'] = 'SUCCESS'
data['like_num'] = like_num
return JsonResponse(data)
# 数据操作失败返回信息的方法
def error_response(message):
data = {}
data['status'] = 'ERROR'
data['message'] = message
return JsonResponse(data)
def like_up(request):
# 得到GET中的数据以及当前用户
user = request.user
# 判断用户是否登录
if not user.is_authenticated:
return error_response('未登录,不能进行点赞操作')
content_type = request.GET.get('content_type')
content_type = ContentType.objects.get(model=content_type)
object_id = request.GET.get('object_id')
is_like = request.GET.get('is_like')
# 创建一个点赞记录
if is_like == 'true':
# 进行点赞,即实例化一个点赞记录
like_record, created = LikeRecord.objects.get_or_create(content_type=content_type, object_id=object_id, like_user=user)
# 通过created来判断点赞记录是否存在,如果存在则不进行点赞,如果不存在则进行点赞数量加一
if created:
# 不存在点赞记录并且已经创建点赞记录,需要将点赞数量加一
like_count, created = LikeCount.objects.get_or_create(content_type=content_type, object_id=object_id)
like_count.like_num += 1
like_count.save()
return success_response(like_count.like_num)
else:
# 已经进行过点赞
return error_response('已经点赞过')
else:
# 取消点赞
# 先查询数据是否存在,存在则进行取消点赞
if LikeRecord.objects.filter(content_type=content_type, object_id=object_id, like_user=user).exists():
# 数据存在,取消点赞
# 删除点赞记录
LikeRecord.objects.get(content_type=content_type, object_id=object_id, like_user=user).delete()
# 判断对应的点赞数量数据是否存在,如果存在则对点赞数量进行减一
like_count, create = LikeCount.objects.get_or_create(content_type=content_type, object_id=object_id)
if create:
# 数据不存在,返回错误信息
return error_response('数据不存在,不能取消点赞')
else:
# 数据存在,对数量进行减一
like_count.like_num -= 1
like_count.save()
return success_response(like_count.like_num)
else:
# 数据不存在,不能取消点赞
return error_response('数据不存在,不能取消点赞')
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,703
|
Mr-big-c/github
|
refs/heads/master
|
/tkinter/离开事件.py
|
"""
离开事件
"""
import tkinter
win = tkinter.Tk()
win.title("hwy")
win.geometry("400x400")
label = tkinter.Label(win, text="python")
label.pack()
def showinfo(event):
print("------")
label.bind("<Leave>", showinfo)
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,704
|
Mr-big-c/github
|
refs/heads/master
|
/快捷办公/播放音乐.py
|
import pygame
import time
# 指定路径
path1 = r"E:\CloudMusic\阿桑 - 一直很安静.mp3"
path2 = r"E:\CloudMusic\GALA - 追梦赤子心.mp3"
# 初始化
pygame.mixer.init()
# 加载音乐
music = pygame.mixer.music.load(path1)
# 播放音乐
pygame.mixer.music.play()
time.sleep(10)
# 设置下一首播放的音乐
music = pygame.mixer.music.load(path2)
pygame.mixer.music.play()
# 延时,让程序循环执行,就能一直播放音乐
time.sleep(20)
# 停止播放
pygame.mixer.music.stop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,705
|
Mr-big-c/github
|
refs/heads/master
|
/快捷办公/os模块.py
|
"""
os模块包含了操作系统的一些普通功能,也可以处理文件
"""
import os
# 获取操作系统类型, nt--Windows, posix--UNIX、Linux
print(os.name)
# 获取操作系统的详细信息,Windows不支持,Linux支持
# print(os.uname())
# 获取所有的环境变量
# print(os.environ)
# # 获取指定的环境变量
# print(os.environ.get("ADAMS_GUI_LOCALE"))
# 获取当前目录 相对路径
# print(os.curdir)
# # 获取绝对路径
# print(os.getcwd())
# 返回指定路径下的所有文件(第一级)
# print(os.listdir(r"D:\python源文件"))
# 创建和删除目录
# os.mkdir("hwy")
# os.rmdir('hwy')
# 获取文件属性
# print(os.stat("django"))
# 重命名文件
# os.rename('hwy', 'myy')
# 删除普通文件
# os.remove("1.txt")
# 运行shell命令
# 打开记事本
# os.system("notepad")
# 打开写字板
# os.system("write")
# 打开画图板
# os.system("mspaint")
# 打开设置
# os.system("msconfig")
# 设置关机 最后一位数值代表延时时间,单位s
# os.system("shutdown -s -t 500")
# 取消关机
# os.system("shutdown -a")
# 关闭进程
# os.system("taskkill /f /im 进程名")
# 查看指定位置的绝对路径
# print(os.path.abspath("."))
# 拼接路径,第二个参数不能以\开头
# path1 = os.path.abspath(".")
# path2 = r"hwy\a"
# print(os.path.join(path1, path2))
# 拆分路径
path1 = r"D:\python源文件\hwy\a.txt"
path2 = "hwy\a"
# # 拆分最底层
# print(os.path.split(path1))
# # 拆分最底层扩展名
# print(os.path.splitext(path1))
# 获取文件名
# print(os.path.basename(path1))
# 判断是否为目录
# print(os.path.isdir(path2))
# 判断文件是否存在
# print(os.path.isfile(path1))
# 判断目录是否存在
# print(os.path.exists(path1))
# 创建了一个目录和一个文件
# os.mkdir("hwy")
# f = open("./hwy/a.txt", "w")
# f.close()
# 获取文件的大小 单位字节
# print(os.path.getsize(path1))
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,706
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/files_system/basics/views.py
|
from django.shortcuts import render, HttpResponse, HttpResponseRedirect
import os
from django.http import StreamingHttpResponse
import base64
import re
from .file_op import file_rm, dir_rm, mkdir_file, rename, unzip, rar
from django.http import JsonResponse
from django.contrib.auth import authenticate, login
from django.contrib import auth
# Create your views here.
# 显示基础路径信息
def index(request):
if request.user.is_anonymous:
return HttpResponseRedirect('/login')
# 基本路径
path = '/Users/hwy/Desktop'
file_list = os.listdir(path)
for i in range(0, len(file_list)):
# 遍历所有的文件,并且判断是否是文件夹
if os.path.isdir(os.path.join(path, file_list[i])):
# 是文件夹,加上文件夹的标志,并且拼接完整路径
file_list[i] = {'states': True, 'url': os.path.join(path, file_list[i]), 'sub_url': file_list[i]}
else:
# 判断是否是压缩文件
if '.rar' in file_list[i]:
file_list[i] = {'states': False, 'url': os.path.join(path, file_list[i]), 'sub_url': file_list[i], 'is_rar': True}
else:
file_list[i] = {'states': False, 'url': os.path.join(path, file_list[i]), 'sub_url': file_list[i], 'is_rar': False}
context = {}
context['file_list'] = file_list
context['num'] = 'test'
context['path'] = path
return render(request, 'index.html', context)
# 获得路径打开文件夹
def open_folder(request):
if request.user.is_anonymous:
return HttpResponseRedirect('/login')
if request.method == 'GET':
path = request.GET.get('url', '')
if path == '':
return HttpResponse('error')
history_url = path.split('/')[4:]
# 再次判断该路径是否是文件夹
if not os.path.isdir(path):
return HttpResponse('is not folder')
# 确定是文件夹,打开文件
# 判断当前路径是否在根目录之下,不是则不能打开
re1_str = '/Users/hwy/(Desktop[\s\S]*?)'
result = re.findall(re1_str, path)
# 判断该路径是不是回收站路径或子路径
if not '/Users/hwy/Desktop/回收站' in path:
if result == []:
return HttpResponse('访问路径不合法')
file_list = os.listdir(path)
for i in range(0, len(file_list)):
# 遍历所有的文件,并且判断是否是文件夹
if os.path.isdir(os.path.join(path, file_list[i])):
# 是文件夹,加上文件夹的标志,并且拼接完整路径
file_list[i] = {'states': True, 'url': os.path.join(path, file_list[i]), 'sub_url': file_list[i]}
else:
# 判断是否是压缩文件
if '.rar' in file_list[i]:
file_list[i] = {'states': False, 'url': os.path.join(path, file_list[i]), 'sub_url': file_list[i], 'is_rar': True}
else:
file_list[i] = {'states': False, 'url': os.path.join(path, file_list[i]), 'sub_url': file_list[i], 'is_rar': False}
context = {}
context['file_list'] = file_list
context['path'] = path
context['history_url'] = history_url
return render(request, 'index.html', context)
else:
return HttpResponse('is not GET request')
# 下载文件
def content(request):
if request.user.is_anonymous:
return HttpResponseRedirect('/login')
if request.method == 'GET':
path = request.GET.get('url', '')
if path == '':
return HttpResponse('error')
# 再次判断路径是否为文件
try:
# 获得文件的后缀名,判断是否是图片格式,如果是图片,则将其转化为base64
if (os.path.splitext(path)[-1]) in ['.jpg', '.png', '.jpeg', '.bmp', '.PNG', '.ico']:
with open(path, "rb") as f:
# b64encode是编码,b64decode是解码
base64_data = base64.b64encode(f.read())
context = {}
context['img_url'] = str(base64_data)[2:-1]
return render(request, 'img.html', context)
with open(path, 'r') as f:
result = f.readlines()
text = ''
for line in result:
text += line
context = {}
context['text'] = text
except:
return HttpResponse('无法打开文件')
return render(request, 'content.html', context)
else:
return HttpResponse('is not GET request')
def download(request):
if request.user.is_anonymous:
return HttpResponseRedirect('/login')
def file_iterator(file_name, chunk_size=512):
with open(file_name, 'rb') as f:
while True:
c = f.read(chunk_size)
if c:
yield c
else:
break
the_file_name = request.GET.get('url')
response = StreamingHttpResponse(file_iterator(the_file_name))
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;filename="{0}"'.format(the_file_name)
return response
# 根据关键字查询路径并且跳转到指定路径
def jump(request):
if request.user.is_anonymous:
return HttpResponseRedirect('/login')
if request.method == 'GET':
keywords = request.GET.get('keywords', '')
if keywords == '':
return HttpResponse('data error')
sum_path = request.GET.get('path', '')
if sum_path == '':
return HttpResponse('data error')
re1_str = '([\s\S]*?' + keywords + ')'
result = re.findall(re1_str, sum_path)[0]
return HttpResponseRedirect('/open_folder?url=' + result)
else:
return HttpResponse('is not GET request')
# 文件删除
def rm_file(request):
if request.user.is_anonymous:
return HttpResponseRedirect('/login')
if request.method == 'GET':
# 获得文件路径
file_path = request.GET.get('url', '')
if file_path == '':
return HttpResponse('file_path is none')
re = file_rm(file_path)
return HttpResponse(re)
else:
return HttpResponse('is not GET request')
pass
# 利用ajax实现文件删除
def rm_file_ajax(request):
if request.user.is_anonymous:
return HttpResponseRedirect('/login')
if request.method == 'GET':
# 得到文件路径
file_path = request.GET.get('path', '')
print(file_path)
if file_path == '':
return HttpResponse('file_path error')
# 判断文件是文件还是文件夹
if os.path.isdir(file_path):
# 是文件夹,使用删除文件夹的方式删除文件夹
re = dir_rm(file_path)
if re != 'rm success':
data = {}
data['status'] = 'error'
data['message'] = re
return JsonResponse(data)
data = {}
data['status'] = 'success'
data['message'] = re
return JsonResponse(data)
# 删除文件
re = file_rm(file_path)
if re != 'rm success':
data = {}
data['status'] = 'error'
data['message'] = re
return JsonResponse(data)
data = {}
data['status'] = 'success'
data['message'] = re
return JsonResponse(data)
else:
return HttpResponse('is not GET reuest')
# 新建文件夹
def mkdir(request):
if request.user.is_anonymous:
return HttpResponseRedirect('/login')
if request.method == 'GET':
# 获得创建文件夹的路径
path = request.GET.get('path', '')
print(path)
# 获得文件夹名称
file_name = request.GET.get('file_name', '')
if file_name == '':
data = {}
data['status'] = 'error'
data['message'] = '文件夹名称不能为空'
return JsonResponse(data)
if path == '':
data = {}
data['status'] = 'error'
data['message'] = 'error'
return JsonResponse(data)
# 路径拼接,得到具体文件夹路径
file_path = os.path.join(path, file_name)
# 创建文件夹
re = mkdir_file(file_path)
if re != 'mkdir success':
data = {}
data['status'] = 'error'
data['message'] = re
return JsonResponse(data)
data = {}
data['status'] = 'success'
data['message'] = re
return JsonResponse(data)
else:
return HttpResponse('is not GET request')
# 返回上一级
def go_back(request):
if request.user.is_anonymous:
return HttpResponseRedirect('/login')
# 得到当前所在的路径
path = request.GET.get('path', '')
if path == '':
return HttpResponse('file path error')
# 对路径进行分割,在去掉最后的部分获得上一级的路径
result = path.split('/')
f = ''
for i in range(1, len(result)-1):
print(result[i])
f += '/' + result[i]
result = f
return HttpResponseRedirect('/open_folder?url=' + result)
# 文件重命名
def file_rename(request):
if request.user.is_anonymous:
return HttpResponseRedirect('/login')
path = request.GET.get('path', '')
name = request.GET.get('name', '')
new_name = request.GET.get('new_name', '')
if new_name == '':
data = {}
data['status'] = 'error'
data['message'] = '文件名不能为空'
return JsonResponse(data)
if (path == '') or (name == ''):
return 'file path is none'
# 判断是否为文件夹
if os.path.isdir(path):
re1_str = '([\s\S]*?)' + name
path = re.findall(re1_str, path)[0]
# 判断新名称是否存在,如果存在则不能重命名
name_list = []
file_list = os.listdir(path)
for i in range(0, len(file_list)):
# 遍历所有的文件,并且判断是否是文件夹
if os.path.isdir(os.path.join(path, file_list[i])):
# 是文件夹
name_list.append(file_list[i])
if new_name in name_list:
data = {}
data['status'] = 'error'
data['message'] = '文件夹已经存在'
return JsonResponse(data)
# 修改文件夹名
result = rename(path, name, new_name)
if result != 'rename success':
data = {}
data['status'] = 'error'
data['message'] = result
return JsonResponse(data)
data = {}
data['status'] = 'success'
data['message'] = result
return JsonResponse(data)
# 对路径进行剪切
re1_str = '([\s\S]*?)' + name
path = re.findall(re1_str, path)[0]
print(path, name, new_name)
# 判断新名称是否存在,如果存在则不能重命名
name_list = []
file_list = os.listdir(path)
for i in range(0, len(file_list)):
# 遍历所有的文件,并且判断是否是文件夹
if not os.path.isdir(os.path.join(path, file_list[i])):
# 是文件
name_list.append(file_list[i])
if new_name in name_list:
data = {}
data['status'] = 'error'
data['message'] = '文件名已经存在'
return JsonResponse(data)
result = rename(path, name, new_name)
if result != 'rename success':
data = {}
data['status'] = 'error'
data['message'] = result
return JsonResponse(data)
data = {}
data['status'] = 'success'
data['message'] = result
return JsonResponse(data)
def test(request):
if request.user.is_anonymous:
return HttpResponseRedirect('/login')
return render(request, 'test.html')
def upload(request):
if request.user.is_anonymous:
return HttpResponseRedirect('/login')
# 处理分片文件的接收与保存
if request.method == 'POST':
my_file = request.FILES.get('file')
if not my_file:
return HttpResponse('文件不存在')
task = request.POST.get('task_id') # 获取文件唯一标识符
# 获取当前路径
path = request.POST.get('path', '')
print(path)
chunk = request.POST.get('chunk', 0) # 获取该分片在所有分片中的序号
filename = '%s%s' % (task, chunk) # 构成该分片唯一标识符,也是保存的文件名
with open(path + '/' + filename, 'wb') as f:
f.write(my_file.read())
return render(request, 'upload.html')
def upload_success(request):
if request.user.is_anonymous:
return HttpResponseRedirect('/login')
# 小文件传输成功后,前端会自动发起请求到此函数,将小文件合并为大文件,并删除缓存的小文件
target_filename = request.GET.get('filename')
task = request.GET.get('task_id') # 获取文件的唯一标识符
# 获得当前路径
path = request.GET.get('path')
print(path)
chunk = 0
with open(path + '/%s' % target_filename, 'wb') as target_file:
while True:
try:
filename = path + '/%s%d' % (task, chunk)
print(filename)
source_file = open(filename, 'rb') # 按序打开每个分片
target_file.write(source_file.read()) # 读取分片内容写入新文件
source_file.close()
except IOError:
break
chunk += 1
os.remove(filename) # 删除该分片,节约空间
return render(request, 'upload.html')
# 解压文件
def file_unzip(request):
if request.user.is_anonymous:
return HttpResponseRedirect('/login')
data= {}
# 得到当前路径
path = request.GET.get('url', '')
if path == '':
data['status'] = 'error'
data['message'] = 'file path error'
return JsonResponse(data)
# 得到该文件的名称
file_name = request.GET.get('file_name', '')
if file_name == '':
data['status'] = 'error'
data['message'] = 'file name error'
return JsonResponse(data)
# 利用正则表达式进行路径切割
re1_str = '([\s\S]*?)' + file_name
sub_path = re.findall(re1_str, path)[0]
result = unzip(path, sub_path)
if result != 'unzip success':
data['status'] = 'error'
data['message'] = 'unzip error'
return JsonResponse(data)
data['status'] = 'success'
data['message'] = '解压完成'
return JsonResponse(data)
# 对文件夹进行压缩
def file_rar(request):
if request.user.is_anonymous:
return HttpResponseRedirect('/login')
data = {}
# 得到文件夹路径
file_path = request.GET.get('path', '')
# 得到文件夹名称
file_name = request.GET.get('file_name', '')
# 得到新的文件名
new_name = request.GET.get('new_name', '')
if file_path == '' or file_name == '':
data['status'] = 'error'
data['message'] = 'file path or file name is none'
return JsonResponse(data)
if new_name == '':
data['status'] = 'error'
data['message'] = '文件名称不能为空'
return JsonResponse(data)
# 对文件夹路径进行修剪,以获得根目录
re1_str = '([\s\S]*?)' + file_name
sub_path = re.findall(re1_str, file_path)[0]
print(sub_path, file_name, new_name)
result = rar(sub_path, file_name, new_name)
if result != 'rar success':
data['status'] = 'error'
data['message'] = 'rar error'
return JsonResponse(data)
data['status'] = 'success'
data['message'] = '压缩完成'
return JsonResponse(data)
# 登陆
def login(request):
if request.method == 'POST':
username = 'hwy'
password = request.POST.get('password', '')
user = authenticate(request, username=username, password=password)
if user is not None:
auth.login(request, user)
return HttpResponseRedirect('/Load')
else:
return HttpResponseRedirect('/login')
return render(request, 'login.html')
# 加载页面
def Load(request):
if request.user.is_anonymous:
return HttpResponseRedirect('/login')
return render(request, 'Load.html')
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,707
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog7-15/ReadNumber/apps.py
|
from django.apps import AppConfig
class ReadnumberConfig(AppConfig):
name = 'ReadNumber'
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,708
|
Mr-big-c/github
|
refs/heads/master
|
/Flask/Flask_Mac/settings/config.py
|
"""
相关参数设置
"""
DEBUG = True
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,709
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-17/Ajax/views.py
|
from django.shortcuts import render, HttpResponse
from django.http import JsonResponse
from myapp.models import Article
from django.core.paginator import Paginator
# Create your views here.
i = 1
def ajax(request):
return render(request, 'Ajax.html')
def ajax_form(request):
data = {}
data['status'] = 'SUCCESS'
data['log_info'] = request.POST['username']
return JsonResponse(data)
# 使用Ajax实现分页功能
def ajax_page(request):
ar = Article.objects.all()
paginator = Paginator(ar, 8)
context = {}
# 使得全局变量i可以局部使用
global i
if request.method == 'GET':
# 刷新一次页面后回到最初的数据
i = 1
# 返回GET请求的模板页面及数据
context['content'] = paginator.get_page(1).object_list
return render(request, 'ajax_page.html', context)
else:
i += 1
# 当每次点击加载更多按钮后会加载下一页的数据并传递给前端页面显示
ar_list = []
ar_id = []
context['content']=paginator.get_page(i).object_list
for ar in context['content']:
ar_list.append(ar.title)
ar_id.append(ar.pk)
data = {}
data['status']='SUCCESS'
data['ar_list']=ar_list
data['ar_id']=ar_id
# 判断是否有下一页数据
if paginator.get_page(i).has_next():
data['has_next'] = 'ok'
else:
data['has_next'] = 'no'
return JsonResponse(data)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,710
|
Mr-big-c/github
|
refs/heads/master
|
/tkinter/text.py
|
"""
文本控件,用于显示多行文本
"""
import tkinter
win = tkinter.Tk()
win.title("hwy")
win.geometry('400x400+400+200')
# 创建滚动条
s = tkinter.Scrollbar()
s.pack(side=tkinter.RIGHT, fill=tkinter.Y)
text = tkinter.Text(win, width=40, height=2)
text.pack(side=tkinter.LEFT, fill=tkinter.Y)
# 关联
s.config(command=text.yview)
text.config(yscrollcommand=s.set)
str = "life is shsdasdasdasdasdaasfw fsdfs sdfsdg gfdgdf \
is shsdasdasdasdasdaasfw fsdfs sdfsdg gfdgdf fgdfg\
life is shsdasdasdasdasdaasfw fsdfs sdfsdg gfdgdf fgdfg\
life is shsdasdasdasdasdaasfw fsdfs sdfsdg gfdgdf fgdfg\
life is shsdasdasdasdasdaasfw fsdfs sdfsdg gfdgdf fgdfg \
is shsdasdasdasdasdaasfw fsdfs sdfsdg gfdgdf fgdfg\
life is shsdasdasdasdasdaasfw fsdfs sdfsdg gfdgdf fgdfg\
life is shsdasdasdasdasdaasfw fsdfs sdfsdg gfdgdf fgdfg\
life is shsdasdasdasdasdaasfw fsdfs sdfsdg gfdgdf fgdfg"
text.insert(tkinter.INSERT, str)
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,711
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-22/Comment/views.py
|
from django.shortcuts import render, HttpResponse
from .models import Comment
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User
from django.http import JsonResponse
from myapp.models import Article
# Create your views here.
# 错误响应的方法
def error_response(message):
data = {}
data['status'] = 'ERROR'
data['message'] = message
return JsonResponse(data)
# 正确响应的方法
def success_response(comment_text, comment_user, comment_time):
data = {}
data['status'] = 'SUCCESS'
data['message'] = '评论成功'
data['comment_text'] = comment_text
data['comment_user'] = str(comment_user)
data['comment_time'] = comment_time
return JsonResponse(data)
def comment(request):
# 判断用户是否登录
if not request.user.is_authenticated:
return error_response('没有登录,不能进行评论')
# 得到对应的评论内容(POST请求)
comment_text = request.POST['comment_text']
# 利用strip()函数去掉两边的空格,判断评论内容是否为空
if comment_text.strip() == '':
return error_response('评论内容为空')
else:
# 得到对应的数据
content_type = request.POST['content_type']
object_id = request.POST['object_id']
# 查询对应的ContentType对象和评论的对象是否存在
if (not ContentType.objects.filter(model=content_type).exists()) or (not Article.objects.filter(pk=object_id).exists()):
return error_response('评论对象不存在')
content_type = ContentType.objects.get(model=content_type)
# 创建评论
comment_data = Comment(content_type=content_type, object_id=object_id, comment_text=comment_text, comment_user=request.user)
comment_data.save()
# 得到评论的时间
comment_time = comment_data.comment_time.strftime('%Y-%m-%d %H:%M:%S')
return success_response(comment_text, request.user, comment_time)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,712
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-15/Recent_Read/migrations/0002_auto_20180804_1703.py
|
# Generated by Django 2.0 on 2018-08-04 09:03
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Recent_Read', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='recent_read',
options={'ordering': ['-Read_time']},
),
migrations.AddField(
model_name='recent_read',
name='is_delete',
field=models.BooleanField(default=False),
),
]
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,713
|
Mr-big-c/github
|
refs/heads/master
|
/练习代码/Flask/flask_web/blueprint1/views/__init__.py
|
# -*- coding: utf-8 -*-
# @File : __init__.py
# @Author: 一稚杨
# @Date : 2018/6/8/008
# @Desc : 初始化,创建一个共享蓝图
from flask import Blueprint
blueprint = Blueprint("web", __name__)
from . import views1, views2
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,714
|
Mr-big-c/github
|
refs/heads/master
|
/快捷办公/word文档读取.py
|
"""
读取word文档
"""
import win32com
import win32com.client
def writeword(path):
# 调用win32的word功能,支持docx和doc两种格式的文件
mw = win32com.client.Dispatch("Word.APPlication")
# 打开文件
doc = mw.Documents.Open(path)
# 以行为单位取数据,取出的格式为str
for data in doc.Paragraphs:
line = data.Range.Text
print(line)
# 关闭文件
doc.Close()
# 关闭word功能
mw.Quit()
path = r"C:\Users\Administrator\Desktop\word.docx"
writeword(path)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,715
|
Mr-big-c/github
|
refs/heads/master
|
/Flask/Flask_win/6.2/url_data.py
|
"""
通过url传递参数
"""
from flask import Flask
# 创建一个Flask应用
app = Flask(__name__)
# 创建视图函数
def index(data1, data2):
return "this is Flask" + data1 + data2
# 创建路由映射
app.add_url_rule("/index/<data1>/<data2>", view_func=index)
# 开启Flask应用
if __name__ == "__main__":
app.run(debug=True)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,716
|
Mr-big-c/github
|
refs/heads/master
|
/快捷办公/获取word文档数据并存储.py
|
"""
存储word文档
"""
import win32com
import win32com.client
def writewordtopath(path, topath):
# 调用win32的word功能,支持docx和doc两种格式的文件
mw = win32com.client.Dispatch("Word.APPlication")
# 打开文件
doc = mw.Documents.Open(path)
# 将数据存储到txt中 2表示存到txt中
doc.SaveAs(topath, 2)
# 关闭文件
doc.Close()
# 关闭word功能
mw.Quit()
path = r"C:\Users\Administrator\Desktop\word.docx"
topath = r"C:\Users\Administrator\Desktop\a.txt"
writewordtopath(path, topath)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,717
|
Mr-big-c/github
|
refs/heads/master
|
/Flask/Flask_win/6.2/web.py
|
"""
Flask基础
"""
# 导入config配置文件中的内容
from config import DEBUG
from flask import Flask
# 创建一个Flask应用
app = Flask(__name__)
# 通过app.config.from_object这个方法去加载配置文件,其中的参数是配置文件的路径
# 返回的结果是一个字典。其中包括一个默认key DEBUG,其value为FALSE
# 需要注意的是:config这个方法的key只能是大写,不能是小写
app.config.from_object("config")
print(app.config["DEBUG"])
# 创建路由方法1,/hello和/hello/是通过重定向实现的
# 其实app.route 也是调用了add_url_rule
# @app.route("/hello/")
# 创建对应的路由所执行的视图函数
def hello():
return "hello Flask, hello python"
def hwy():
return "this is home page"
# 创建路由方法2:通过绑定路由与视图函数实现
# 参数1:路由,参数2:视图函数
app.add_url_rule('/hello', view_func=hello)
app.add_url_rule("/index", view_func=hwy)
# 判断是否是直接通过该函数来加载开启服务器,
# 如果不是,则不会执行run方法,因为通常在生产环境下,都是通过如nginx等
# 方法去部署服务器,所以不会通过run来启动服务器,而是通过nginx来开启,
# 如果同时开启了多个服务器,这是不允许的,所以需要通过if来判断
if __name__ == "__main__":
# 运行Flask应用,并开启调试模式
# 0.0.0.0是让可以通过其他的服务器来访问
app.run(host="0.0.0.0",debug=DEBUG)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,718
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-19/Comment/admin.py
|
from django.contrib import admin
from .models import Comment
# Register your models here.
class CommentAdmin(admin.ModelAdmin):
list_display = ('pk', 'content_object', 'comment_time', 'comment_user', 'comment_text')
admin.site.register(Comment, CommentAdmin)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,719
|
Mr-big-c/github
|
refs/heads/master
|
/tkinter/scale.py
|
"""
scale 控件,可以通过拖拽指示器来改变变量的值,类似音量的控制
"""
import tkinter
win = tkinter.Tk()
win.title("hwy")
win.geometry("400x400")
# from_ 指定起始值,to指定结束值 orient指定方向,HORIZONTAL水平,
# VERTICAL垂直
scale = tkinter.Scale(win, from_=0, to=100, orient=tkinter.HORIZONTAL, tickinterval=10, length=200)
scale.set(10)
print(scale.get())
scale.pack()
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,720
|
Mr-big-c/github
|
refs/heads/master
|
/快捷办公/控制窗体的显示和隐藏.py
|
import win32con
import win32gui
import time
while True:
winQQ = win32gui.FindWindow("TXGuiFoundation", "QQ")
win32gui.ShowWindow(winQQ, win32con.SW_SHOW)
time.sleep(1)
win32gui.ShowWindow(winQQ, win32con.SW_HIDE)
time.sleep(1)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,721
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-13/Recent_Read/apps.py
|
from django.apps import AppConfig
class RecentReadConfig(AppConfig):
name = 'Recent_Read'
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,722
|
Mr-big-c/github
|
refs/heads/master
|
/实战项目/圆弧插补/圆弧插补.py
|
"""
圆弧插补
"""
import numpy as np
import matplotlib.pyplot as plt
import tkinter
def show():
# 得到对应的参数
xo = float(entry.get())
yo = float(entry1.get())
xe = float(entry2.get())
ye = float(entry3.get())
x0 = float(entry4.get())
y0 = float(entry5.get())
mode = R1.get()
r = ((xo - x0)**2 + (yo - y0)**2)**0.5
# 计算圆弧对应的角度
ag = angle(xo, yo, xe, ye, x0, y0, r)
region(xo, yo, xe, ye, x0, y0, ag, r, mode)
# 计算圆弧对应的角度
def angle(xo, yo, xe, ye, x0, y0, r):
c = ((xe - xo)**2 + (ye - yo)**2)
ag = 1 - (c/(2 * r**2))
return ag
# 划分象限区域
def region(xo, yo, xe, ye, x0, y0, ag, r, mode):
r = r**2
if mode == 22:
# 逆圆插补
# 圆弧起点和终点均在第一象限
if xo >= x0 and yo >= y0 and xe >= x0 and ye >= y0 and xo >= xe:
if xo == xe:
x = np.linspace(xo, x0, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 - r**0.5, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 - r**0.5, x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 + r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 + r**0.5, xe, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin(xo, yo, x0, y0 + r**0.5, x0, y0, r, 1)
runin(x0, y0 + r**0.5, x0 - r**0.5, y0, x0, y0, r, 2)
runin(x0 - r**0.5, y0, x0, y0 - r**0.5, x0, y0, r, 3)
runin(x0, y0 - r**0.5, x0 + r**0.5, y0, x0, y0, r, 4)
runin(x0 + r**0.5, y0, xe, ye, x0, y0, r, 1)
plt.show()
else:
x = np.linspace(xo, xe, 1000) # 这个表示在-5到5之间生成1000个x值
# 对上述生成的1000个数循环用sigmoid公式求对应的y
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y) # 用上述生成的1000个xy值对生成1000个点
runin(xo, yo, xe, ye, x0, y0, r, 1)
plt.show()
# 起点在第一象限,终点在第二象限
elif xo >= x0 and yo >= y0 and xe < x0 and ye >= y0 and xo > xe:
x = np.linspace(xo, x0, 1000) # 这个表示在-5到5之间生成1000个x值
# 对上述生成的1000个数循环用sigmoid公式求对应的y
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y) # 用上述生成的1000个xy值对生成1000个点
x = np.linspace(x0, xe, 1000) # 这个表示在-5到5之间生成1000个x值
# 对上述生成的1000个数循环用sigmoid公式求对应的y
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y) # 用上述生成的1000个xy值对生成1000个点
runin(xo, yo, x0, y0 + r**0.5, x0, y0, r, 1)
runin(x0, y0 + r**0.5, xe, ye, x0, y0, r, 2)
plt.show()
# 起点在第一象限,终点在第三象限
elif xo >= x0 and yo >= y0 and xe < x0 and ye < y0 and xo > xe:
x = np.linspace(xo, x0, 1000) # 这个表示在-5到5之间生成1000个x值
# 对上述生成的1000个数循环用sigmoid公式求对应的y
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y) # 用上述生成的1000个xy值对生成1000个点
x = np.linspace(x0, (x0 - r**0.5), 1000) # 这个表示在-5到5之间生成1000个x值
# 对上述生成的1000个数循环用sigmoid公式求对应的y
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y) # 用上述生成的1000个xy值对生成1000个点
x = np.linspace((x0 - r**0.5), xe, 1000) # 这个表示在-5到5之间生成1000个x值
# 对上述生成的1000个数循环用sigmoid公式求对应的y
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y) # 用上述生成的1000个xy值对生成1000个点
runin(xo, yo, x0, y0 + r**0.5, x0, y0, r, 1)
runin(x0, y0 + r**0.5, x0 - r**0.5, y0, x0, y0, r, 2)
runin(x0 - r**0.5, y0, xe, ye, x0, y0, r, 3)
plt.show()
# 起点在第一象限,终点在第四象限
elif xo >= x0 and yo >= y0 and xe > x0 and ye < y0 and yo > ye:
x = np.linspace(xo, x0, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, (x0 - r**0.5), 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace((x0 - r**0.5), x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, xe, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin(xo, yo, x0, y0 + r**0.5, x0, y0, r, 1)
runin(x0, y0 + r**0.5, x0 - r**0.5, y0, x0, y0, r, 2)
runin(x0 - r**0.5, y0, x0, y0 - r**0.5, x0, y0, r, 3)
runin(x0, y0 - r**0.5, xe, ye, x0, y0, r, 4)
plt.show()
# 起点在第二象限,终点在第二象限
elif xo <= x0 and yo >= y0 and xe <= x0 and ye >= y0 and xo >= xe:
if xo == xe:
x = np.linspace(xo, x0 - r**0.5, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 - r**0.5, x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 + r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 + r**0.5, x0, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, xe, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin(xo, yo, x0 - r**0.5, y0, x0, y0, r, 2)
runin(x0 - r**0.5, y0, x0, y0 - r**0.5, x0, y0, r, 3)
runin(x0, y0 - r**0.5, x0 + r**0.5, y0, x0, y0, r, 4)
runin(x0 + r**0.5, y0, x0, y0 + r**0.5, x0, y0, r, 1)
runin(x0, y0 + r**0.5, xe, ye, x0, y0, r, 2)
plt.show()
else:
x = np.linspace(xo, xe, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin(xo, yo, xe, ye, x0, y0, r, 2)
plt.show()
# 起点在第二象限,终点在第三象限
elif xo <= x0 and yo >= y0 and xe <= x0 and ye <= y0 and ye < yo:
x = np.linspace(xo, x0 - r**0.5, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 - r**0.5, xe, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin(xo, yo, x0 - r**0.5, y0, x0, y0, r, 2)
runin(x0 - r**0.5, y0, xe, ye, x0, y0, r, 3)
plt.show()
# 起点在第二象限,终点在第四象限
elif xo <= x0 and yo >= y0 and xe >= x0 and ye <= y0 and xe > xo:
x = np.linspace(xo, x0 - r**0.5, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 - r**0.5, x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, xe, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin(xo, yo, x0 - r**0.5, y0, x0, y0, r, 2)
runin(x0 - r**0.5, y0, x0, y0 - r**0.5, x0, y0, r, 3)
runin(x0, y0 - r**0.5, xe, ye, x0, y0, r, 4)
plt.show()
# 起点在第二象限,终点在第一象限
elif xo <= x0 and yo >= y0 and xe >= x0 and ye >= y0 and xe > xo:
x = np.linspace(xo, x0 - r**0.5, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 - r**0.5, x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 + r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 + r**0.5, xe, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin(xo, yo, x0 - r**0.5, y0, x0, y0, r, 2)
runin(x0 - r**0.5, y0, x0, y0 - r**0.5, x0, y0, r, 3)
runin(x0, y0 - r**0.5, x0 + r**0.5, y0, x0, y0, r, 4)
runin(x0 + r**0.5, y0, xe, ye, x0, y0, r, 1)
plt.show()
# 起点和终点在三象限
elif xo <= x0 and yo <= y0 and xe <= x0 and ye <= y0 and xe >= xo:
if xe == xo:
x = np.linspace(xo, x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 + r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 + r**0.5, x0, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 - r**0.5, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 - r**0.5, xe, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin(xo, yo, x0, y0 - r**0.5, x0, y0, r, 3)
runin(x0, y0 - r**0.5, x0 + r**0.5, y0, x0, y0, r, 4)
runin(x0 + r**0.5, y0, x0, y0 + r**0.5, x0, y0, r, 1)
runin(x0, y0 + r**0.5, x0 - r**0.5, y0, x0, y0, r, 2)
runin(x0 - r**0.5, y0, xe, ye, x0, y0, r, 3)
plt.show()
else:
x = np.linspace(xo, xe, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin(xo, yo, xe, ye, x0, y0, r, 3)
plt.show()
# 起点在三象限,终点在第四象限
elif xo <= x0 and yo <= y0 and xe >= x0 and ye <= y0 and xe > xo:
x = np.linspace(xo, x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, xe, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin(xo, yo, x0, y0 - r**0.5, x0, y0, r, 3)
runin(x0, y0 - r**0.5, xe, ye, x0, y0, r, 4)
plt.show()
# 起点在三象限,终点在第一象限
elif xo <= x0 and yo <= y0 and xe >= x0 and ye >= y0 and xe > x0:
x = np.linspace(xo, x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 + r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 + r**0.5, xe, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin(xo, yo, x0, y0 - r**0.5, x0, y0, r, 3)
runin(x0, y0 - r**0.5, x0 + r**0.5, y0, x0, y0, r, 4)
runin(x0 + r**0.5, y0, xe, ye, x0, y0, r, 1)
plt.show()
# 起点在三象限,终点在第二象限
elif xo <= x0 and yo <= y0 and xe <= x0 and ye >= y0 and ye > yo:
x = np.linspace(xo, x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 + r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 + r**0.5, x0, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, xe, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin(xo, yo, x0, y0 - r**0.5, x0, y0, r, 3)
runin(x0, y0 - r**0.5, x0 + r**0.5, y0, x0, y0, r, 4)
runin(x0 + r**0.5, y0, x0, y0 + r**0.5, x0, y0, r, 1)
runin(x0, y0 + r**0.5, xe, ye, x0, y0, r, 2)
plt.show()
# 起点和终点在四象限
elif xo >= x0 and yo <= y0 and xe >= x0 and ye <= y0:
if ye == yo:
x = np.linspace(xo, x0 + r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 + r**0.5, x0, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 - r**0.5, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 - r**0.5, x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, xe, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin(xo, yo, x0 + r**0.5, y0, x0, y0, r, 4)
runin(x0 + r**0.5, y0, x0, y0 + r**0.5, x0, y0, r, 1)
runin(x0, y0 + r**0.5, x0 - r**0.5, y0, x0, y0, r, 2)
runin(x0 - r**0.5, y0, x0, y0 - r**0.5, x0, y0, r, 3)
runin(x0, y0 - r**0.5, xe, ye, x0, y0, r, 4)
plt.show()
else:
x = np.linspace(xo, xe, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin(xo, yo, xe, ye, x0, y0, r, 4)
plt.show()
# 起点在四象限,终点在第一象限
elif xo >= x0 and yo <= y0 and xe >= x0 and ye >= y0 and ye > yo:
x = np.linspace(xo, x0 + r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 + r**0.5, xe, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin(xo, yo, x0 + r**0.5, y0, x0, y0, r, 4)
runin(x0 + r**0.5, y0, xe, ye, x0, y0, r, 1)
plt.show()
# 起点在四象限,终点在第二象限
elif xo >= x0 and yo <= y0 and xe <= x0 and ye >= y0 and xo > xe:
x = np.linspace(xo, x0 + r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 + r**0.5, x0, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, xe, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin(xo, yo, x0 + r**0.5, y0, x0, y0, r, 4)
runin(x0 + r**0.5, y0, x0, y0 + r**0.5, x0, y0, r, 1)
runin(x0, y0 + r**0.5, xe, ye, x0, y0, r, 2)
plt.show()
# 起点在四象限,终点在第三象限
elif xo >= x0 and yo <= y0 and xe <= x0 and ye <= y0 and xo > xe:
x = np.linspace(xo, x0 + r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 + r**0.5, x0, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 - r**0.5, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 - r**0.5, xe, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin(xo, yo, x0 + r**0.5, y0, x0, y0, r, 4)
runin(x0 + r**0.5, y0, x0, y0 + r**0.5, x0, y0, r, 1)
runin(x0, y0 + r**0.5, x0 - r**0.5, y0, x0, y0, r, 2)
runin(x0 - r**0.5, y0, xe, ye, x0, y0, r, 3)
plt.show()
# 顺圆插补
else:
# 圆弧起点和终点均在第一象限
if xo >= x0 and yo >= y0 and xe >= x0 and ye >= y0 and xo <= xe:
if xo == xe:
x = np.linspace(xo, x0 + r**0.5, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 + r**0.5, x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 - r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 - r**0.5, x0, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, xe, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin1(xo, yo, x0 + r**0.5, y0, x0, y0, r, 1)
runin1(x0 + r**0.5, y0, x0, y0 - r**0.5, x0, y0, r, 4)
runin1(x0, y0 - r**0.5, x0 - r**0.5, y0, x0, y0, r, 3)
runin1(x0 - r**0.5, y0, x0, y0 + r**0.5, x0, y0, r, 2)
runin1(x0, y0 + r**0.5, xe, ye, x0, y0, r, 1)
plt.show()
else:
x = np.linspace(xo, xe, 1000) # 这个表示在-5到5之间生成1000个x值
# 对上述生成的1000个数循环用sigmoid公式求对应的y
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y) # 用上述生成的1000个xy值对生成1000个点
runin1(xo, yo, xe, ye, x0, y0, r, 1)
plt.show()
# 圆弧起点在第一象限, 终点在第四象限
elif xo >= x0 and yo >= y0 and xe >= x0 and ye <= y0 and yo > ye:
x = np.linspace(xo, x0 + r**0.5, 1000) # 这个表示在-5到5之间生成1000个x值
# 对上述生成的1000个数循环用sigmoid公式求对应的y
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y) # 用上述生成的1000个xy值对生成1000个点
x = np.linspace(x0 + r**0.5, xe, 1000) # 这个表示在-5到5之间生成1000个x值
# 对上述生成的1000个数循环用sigmoid公式求对应的y
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y) # 用上述生成的1000个xy值对生成1000个点
runin1(xo, yo, x0 + r**0.5, y0, x0, y0, r, 1)
runin1(x0 + r**0.5, y0, xe, ye, x0, y0, r, 4)
plt.show()
# 圆弧起点在第一象限, 终点在第三象限
elif xo >= x0 and yo >= y0 and xe <= x0 and ye <= y0 and xo > xe:
x = np.linspace(xo, x0 + r**0.5, 1000) # 这个表示在-5到5之间生成1000个x值
# 对上述生成的1000个数循环用sigmoid公式求对应的y
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 + r**0.5, x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, xe, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin1(xo, yo, x0 + r**0.5, y0, x0, y0, r, 1)
runin1(x0 + r**0.5, y0, x0, y0 - r**0.5, x0, y0, r, 4)
runin1(x0, y0 - r**0.5, xe, ye, x0, y0, r, 3)
plt.show()
# 圆弧起点在第一象限, 终点在第二象限
elif xo >= x0 and yo >= y0 and xe <= x0 and ye >= y0 and xo > xe:
x = np.linspace(xo, x0 + r**0.5, 1000) # 这个表示在-5到5之间生成1000个x值
# 对上述生成的1000个数循环用sigmoid公式求对应的y
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 + r**0.5, x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 - r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 - r**0.5, xe, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin1(xo, yo, x0 + r**0.5, y0, x0, y0, r, 1)
runin1(x0 + r**0.5, y0, x0, y0 - r**0.5, x0, y0, r, 4)
runin1(x0, y0 - r**0.5, x0 - r**0.5, y0, x0, y0, r, 3)
runin1(x0 - r**0.5, y0, xe, ye, x0, y0, r, 2)
plt.show()
# 圆弧起点和终点均在第二象限
elif xo <= x0 and yo >= y0 and xe <= x0 and ye >= y0 and xo <= xe:
if xo == xe:
x = np.linspace(xo, x0, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 + r**0.5, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 + r**0.5, x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 - r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 - r**0.5, xe, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin1(xo, yo, x0, y0 + r**0.5, x0, y0, r, 2)
runin1(x0, y0 + r**0.5, x0 + r**0.5, y0, x0, y0, r, 1)
runin1(x0 + r**0.5, y0, x0, y0 - r**0.5, x0, y0, r, 4)
runin1(x0, y0 - r**0.5, x0 - r**0.5, y0, x0, y0, r, 3)
runin1(x0 - r**0.5, y0, xe, ye, x0, y0, r, 2)
plt.show()
else:
x = np.linspace(xo, xe, 1000) # 这个表示在-5到5之间生成1000个x值
# 对上述生成的1000个数循环用sigmoid公式求对应的y
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y) # 用上述生成的1000个xy值对生成1000个点
runin1(xo, yo, xe, ye, x0, y0, r, 2)
plt.show()
# 圆弧起点第二象限,终点在第一象限
elif xo <= x0 and yo >= y0 and xe >= x0 and ye >= y0 and xo < xe:
x = np.linspace(xo, x0, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, xe, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin1(xo, yo, x0, y0 + r**0.5, x0, y0, r, 2)
runin1(x0, y0 + r**0.5, xe, ye, x0, y0, r, 1)
plt.show()
# 圆弧起点第二象限,终点在第四象限
elif xo <= x0 and yo >= y0 and xe >= x0 and ye <= y0 and xo < xe:
x = np.linspace(xo, x0, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 + r**0.5, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 + r**0.5, xe, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin1(xo, yo, x0, y0 + r**0.5, x0, y0, r, 2)
runin1(x0, y0 + r**0.5, x0 + r**0.5, y0, x0, y0, r, 1)
runin1(x0 + r**0.5, y0, xe, ye, x0, y0, r, 4)
plt.show()
# 圆弧起点第二象限,终点在第三象限
elif xo <= x0 and yo >= y0 and xe <= x0 and ye <= y0 and yo > ye:
x = np.linspace(xo, x0, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 + r**0.5, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 + r**0.5, x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, xe, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin1(xo, yo, x0, y0 + r**0.5, x0, y0, r, 2)
runin1(x0, y0 + r**0.5, x0 + r**0.5, y0, x0, y0, r, 1)
runin1(x0 + r**0.5, y0, x0, y0 - r**0.5, x0, y0, r, 4)
runin1(x0, y0 - r**0.5, xe, ye, x0, y0, r, 3)
plt.show()
# 圆弧起点和终点均在第三象限
elif xo <= x0 and yo <= y0 and xe <= x0 and ye <= y0 and xo >= xe:
if xo == xe:
x = np.linspace(xo, x0 - r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 - r**0.5, x0, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 + r**0.5, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 + r**0.5, x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, xe, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin1(xo, yo, x0 - r**0.5, y0, x0, y0, r, 3)
runin1(x0 - r**0.5, y0, x0, y0 + r**0.5, x0, y0, r, 2)
runin1(x0, y0 + r**0.5, x0 + r**0.5, y0, x0, y0, r, 1)
runin1(x0 + r**0.5, y0, x0, y0 - r**0.5, x0, y0, r, 4)
runin1(x0, y0 - r**0.5, xe, ye, x0, y0, r, 3)
plt.show()
else:
x = np.linspace(xo, xe, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin1(xo, yo, xe, ye, x0, y0, r, 3)
plt.show()
# 圆弧起点在第三象限,终点在第二象限
elif xo <= x0 and yo <= y0 and xe <= x0 and ye >= y0 and ye > yo:
x = np.linspace(xo, x0 - r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 - r**0.5, xe, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin1(xo, yo, x0 - r**0.5, y0, x0, y0, r, 3)
runin1(x0 - r**0.5, y0, xe, ye, x0, y0, r, 2)
plt.show()
# 圆弧起点在第三象限,终点在第一象限
elif xo <= x0 and yo <= y0 and xe >= x0 and ye >= y0 and xe > xo:
x = np.linspace(xo, x0 - r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 - r**0.5, x0, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, xe, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin1(xo, yo, x0 - r**0.5, y0, x0, y0, r, 3)
runin1(x0 - r**0.5, y0, x0, y0 + r**0.5, x0, y0, r, 2)
runin1(x0, y0 + r**0.5, xe, ye, x0, y0, r, 1)
plt.show()
# 圆弧起点在第三象限,终点在第四象限
elif xo <= x0 and yo <= y0 and xe >= x0 and ye <= y0 and xe > xo:
x = np.linspace(xo, x0 - r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 - r**0.5, x0, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 + r**0.5, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 + r**0.5, xe, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin1(xo, yo, x0 - r**0.5, y0, x0, y0, r, 3)
runin1(x0 - r**0.5, y0, x0, y0 + r**0.5, x0, y0, r, 2)
runin1(x0, y0 + r**0.5, x0 + r**0.5, y0, x0, y0, r, 1)
runin1(x0 + r**0.5, y0, xe, ye, x0, y0, r, 4)
plt.show()
# 圆弧起点和终点均在第四象限
elif xo >= x0 and yo <= y0 and xe >= x0 and ye <= y0 and xo >= xe:
if xo == xe:
x = np.linspace(xo, x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 - r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 - r**0.5, x0, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 + r**0.5, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 + r**0.5, xe, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin1(xo, yo, x0, y0 - r**0.5, x0, y0, r, 4)
runin1(x0, y0 - r**0.5, x0 - r**0.5, y0, x0, y0, r, 3)
runin1(x0 - r**0.5, y0, x0, y0 + r**0.5, x0, y0, r, 2)
runin1(x0, y0 + r**0.5, x0 + r**0.5, y0, x0, y0, r, 1)
runin1(x0 + r**0.5, y0, xe, ye, x0, y0, r, 4)
plt.show()
else:
x = np.linspace(xo, xe, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin1(xo, yo, xe, ye, x0, y0, r, 4)
plt.show()
# 圆弧起点在第四象限,终点在第三象限
elif xo >= x0 and yo <= y0 and xe <= x0 and ye <= y0 and xo > xe:
x = np.linspace(xo, x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, xe, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin1(xo, yo, x0, y0 - r**0.5, x0, y0, r, 4)
runin1(x0, y0 - r**0.5, xe, ye, x0, y0, r, 3)
plt.show()
# 圆弧起点在第四象限,终点在第二象限
elif xo >= x0 and yo <= y0 and xe <= x0 and ye >= y0 and xo > xe:
x = np.linspace(xo, x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 - r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 - r**0.5, xe, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin1(xo, yo, x0, y0 - r**0.5, x0, y0, r, 4)
runin1(x0, y0 - r**0.5, x0 - r**0.5, y0, x0, y0, r, 3)
runin1(x0 - r**0.5, y0, xe, ye, x0, y0, r, 2)
plt.show()
# 圆弧起点在第四象限,终点在第一象限
elif xo >= x0 and yo <= y0 and xe >= x0 and ye >= y0 and ye > yo:
x = np.linspace(xo, x0, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, x0 - r**0.5, 1000)
y = [-((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0 - r**0.5, x0, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
x = np.linspace(x0, xe, 1000)
y = [((r - (i - x0)**2)**0.5) + y0 for i in x]
plt.axis("equal")
plt.plot(x, y)
runin1(xo, yo, x0, y0 - r**0.5, x0, y0, r, 4)
runin1(x0, y0 - r**0.5, x0 - r**0.5, y0, x0, y0, r, 3)
runin1(x0 - r**0.5, y0, x0, y0 + r**0.5, x0, y0, r, 2)
runin1(x0, y0 + r**0.5, xe, ye, x0, y0, r, 1)
plt.show()
# 逆圆插补
def runin(xo, yo, xe, ye, x0, y0, r, k):
p = float(e6.get())
sum = int(abs(xo - xe) + abs(yo - ye))
for i in range(int(sum/p)):
if i == 0:
txt.insert(tkinter.INSERT, "(" + str(xo) + "," + str(yo) + ")" + "\n")
if k == 1:
result3 = in_1(xo, yo, x0, y0, r)
elif k == 2:
result3 = in_2(xo, yo, x0, y0, r)
elif k == 3:
result3 = in_3(xo, yo, x0, y0, r)
elif k == 4:
result3 = in_4(xo, yo, x0, y0, r)
# print(result3)
plt.pause(0.5)
plt.plot((xo, result3[0]), (yo, result3[1]))
xo = result3[0]
yo = result3[1]
txt.insert(tkinter.INSERT, "(" + str(xo) + "," + str(yo) + ")" + "\n")
# 顺圆插补
def runin1(xo, yo, xe, ye, x0, y0, r, k):
p = float(e6.get())
sum = int(abs(xo - xe) + abs(yo - ye))
for i in range(int(sum/p)):
if i == 0:
txt.insert(tkinter.INSERT, "(" + str(xo) + "," + str(yo) + ")" + "\n")
# print(xo, yo)
if k == 1:
result3 = in_1_1(xo, yo, x0, y0, r)
elif k == 2:
result3 = in_1_2(xo, yo, x0, y0, r)
elif k == 3:
result3 = in_1_3(xo, yo, x0, y0, r)
elif k == 4:
result3 = in_1_4(xo, yo, x0, y0, r)
# print(result3)
plt.pause(0.5)
plt.plot((xo, result3[0]), (yo, result3[1]))
xo = result3[0]
yo = result3[1]
txt.insert(tkinter.INSERT, "(" + str(xo) + "," + str(yo) + ")" + "\n")
# 插补计算模块
# 在第一象限的插补
def in_1(x, y, x0, y0, r):
p = float(e6.get())
fm = (x - x0)**2 + (y - y0)**2 - r
if fm >= 0:
x = x - p
y = y
else:
y = y + p
x = x
return (x, y)
def in_1_1(x, y, x0, y0, r):
p = float(e6.get())
fm = (x - x0)**2 + (y - y0)**2 - r
if fm >= 0:
x = x
y = y - p
else:
y = y
x = x + p
return (x, y)
# 在第二象限的插补
def in_2(x, y, x0, y0, r):
p = float(e6.get())
fm = (x - x0)**2 + (y - y0)**2 - r
if fm >= 0:
x = x
y = y - p
else:
y = y
x = x - p
return (x, y)
def in_1_2(x, y, x0, y0, r):
p = float(e6.get())
fm = (x - x0)**2 + (y - y0)**2 - r
if fm >= 0:
x = x + p
y = y
else:
y = y + p
x = x
return (x, y)
# 在第三象限的插补
def in_3(x, y, x0, y0, r):
p = float(e6.get())
fm = (x - x0)**2 + (y - y0)**2 - r
if fm >= 0:
x = x + p
y = y
else:
y = y - p
x = x
return (x, y)
def in_1_3(x, y, x0, y0, r):
p = float(e6.get())
fm = (x - x0)**2 + (y - y0)**2 - r
if fm >= 0:
x = x
y = y + p
else:
y = y
x = x - p
return (x, y)
# 在第四象限的插补
def in_4(x, y, x0, y0, r):
p = float(e6.get())
fm = (x - x0)**2 + (y - y0)**2 - r
if fm >= 0:
x = x
y = y + p
else:
y = y
x = x + p
return (x, y)
def in_1_4(x, y, x0, y0, r):
p = float(e6.get())
fm = (x - x0)**2 + (y - y0)**2 - r
if fm >= 0:
x = x - p
y = y
else:
y = y - p
x = x
return (x, y)
# 清除数据
def clear():
txt.delete(0.0, tkinter.END)
# tkinter创建窗口
win = tkinter.Tk()
win.title("hwy")
win.geometry("600x400")
win.resizable(width=False, height=False)
label = tkinter.Label(win, text="圆弧插补")
label.pack()
button = tkinter.Button(win, text="插补计算", command=show)
button.place(x=250, y=350)
R1 = tkinter.IntVar()
radio3 = tkinter.Radiobutton(win, text="顺圆插补", value=11, variable=R1)
radio3.place(x=100, y=300)
radio4 = tkinter.Radiobutton(win, text="逆圆插补", value=22, variable=R1)
radio4.place(x=200, y=300)
R1.set(11)
label2 = tkinter.Label(win, text="起点坐标:Xo=")
label2.place(x=100, y=50)
e = tkinter.Variable()
entry = tkinter.Entry(win, textvariable=e)
e.set(0)
entry.place(x=200, y=50)
label3 = tkinter.Label(win, text="起点坐标:Yo=")
label3.place(x=100, y=80)
e1 = tkinter.Variable()
entry1 = tkinter.Entry(win, textvariable=e1)
e1.set(10)
entry1.place(x=200, y=80)
label4 = tkinter.Label(win, text="终点坐标:Xe=")
label4.place(x=100, y=110)
e2 = tkinter.Variable()
entry2 = tkinter.Entry(win, textvariable=e2)
e2.set(10)
entry2.place(x=200, y=110)
label5 = tkinter.Label(win, text="终点坐标:Ye=")
label5.place(x=100, y=140)
e3 = tkinter.Variable()
entry3 = tkinter.Entry(win, textvariable=e3)
e3.set(0)
entry3.place(x=200, y=140)
label6 = tkinter.Label(win, text="圆心坐标:X=")
label6.place(x=100, y=170)
e4 = tkinter.Variable()
entry4 = tkinter.Entry(win, textvariable=e4)
e4.set(0)
entry4.place(x=200, y=170)
label7 = tkinter.Label(win, text="圆心坐标:Y=")
label7.place(x=100, y=200)
e5 = tkinter.Variable()
entry5 = tkinter.Entry(win, textvariable=e5)
e5.set(0)
entry5.place(x=200, y=200)
label8 = tkinter.Label(win, text="脉冲当量:P=")
label8.place(x=100, y=230)
e6 = tkinter.Variable()
entry6 = tkinter.Entry(win, textvariable=e6)
e6.set(1)
entry6.place(x=200, y=230)
label9 = tkinter.Label(win, text="精度:A=")
label9.place(x=100, y=260)
e7 = tkinter.Variable()
entry7 = tkinter.Entry(win, textvariable=e7)
e7.set(5)
entry7.place(x=200, y=260)
# 显示坐标值
txt = tkinter.Text(win)
txt.place(x=400, y=30)
button1 = tkinter.Button(win, text="清除坐标", command=clear)
button1.place(x=340, y=350)
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,723
|
Mr-big-c/github
|
refs/heads/master
|
/tkinter/entry.py
|
"""
输入控件
"""
import tkinter
win = tkinter.Tk()
win.title('黄文杨') # 设置标题
win.geometry('400x400+200+200') # 设置大小和位置
e = tkinter.Variable()
entry = tkinter.Entry(win, textvariable=e)
entry.pack()
e.set("hwy is a good man") # 设置默认值
print(entry.get()) # 获取值
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,724
|
Mr-big-c/github
|
refs/heads/master
|
/Flask/Flask_Mac/blueprint1/views1.py
|
"""
视图函数1,继承于蓝图1
"""
from flask import Blueprint, render_template
# 实例化一个蓝图
blueprint1 = Blueprint('blueprint1', __name__)
# 利用blueprint1来创建视图函数
@blueprint1.route('/index/')
def index():
return "this is blueprint1"
@blueprint1.route('/index2/')
def index2():
return render_template('index2.html')
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,725
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-22/myapp/admin.py
|
from django.contrib import admin
from .models import *
# Register your models here.
# 注册模型Article
class ArticleAdmin(admin.ModelAdmin):
list_display = ('id', 'title', 'author', 'text', 'readnum', 'status')
actions = ['publish_status', 'withdraw_status']
# 添加admin动作(发表文章)
def publish_status(self, request, queryset):
queryset.update(status='p')
# 指定后台界面动作的关键词
publish_status.short_description = "发布文章"
# 添加admin动作(撤回文章)
def withdraw_status(self, request, queryset):
queryset.update(status='w')
withdraw_status.short_description = '撤回文章'
# 注册模型Read_Num
class Read_NumAdmin(admin.ModelAdmin):
list_display = ('id', 'read_num_data', 'article')
admin.site.register(Article, ArticleAdmin)
admin.site.register(Read_Num, Read_NumAdmin)
admin.site.register(Test)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,726
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-22/Recent_Read/admin.py
|
from django.contrib import admin
from .models import Recent_Read
# Register your models here.
class Recent_ReadAdmin(admin.ModelAdmin):
list_display = ('content_object', 'Read_time', 'user')
admin.site.register(Recent_Read, Recent_ReadAdmin)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,727
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-21/myapp/templatetags/template_test.py
|
# -*- coding: utf-8 -*-
# @File : template_test.py.py
# @Author: 一稚杨
# @Date : 2018/8/12/012
# @Desc :
from django import template
from myapp.models import Article
register = template.Library()
@register.simple_tag
def test(pk):
author = Article.objects.get(pk=pk).author
if author == 'hwy':
author = 'up主'
return author
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,728
|
Mr-big-c/github
|
refs/heads/master
|
/实战项目/ug插件安装/源代码.py
|
"""
tkinter 实现ug外挂安装
"""
#coding:utf-8
import tkinter
from tkinter.filedialog import askdirectory
import webbrowser
import os
import re
import sys
win = tkinter.Tk()
win.title("ug插件安装器")
win.geometry("400x200")
win.iconbitmap("C:\\Users\\Administrator\\Desktop\\个人博客\\nx.ico")
# 选择路径函数
def filepath1():
path_ = askdirectory()
path1.set(path_)
def filepath2():
path_ = askdirectory()
path2.set(path_)
def showinfo():
path = entry1.get()
newpath = os.path.join(path, "UGII\\menus\\custom_dirs.dat")
# 获得当前绝对路径
abspath = sys.path[0]
# 以追加模式打开
with open(newpath, "a", encoding='gbk') as f:
f.write(abspath + "\n")
# 修改源程序的路径
path1 = os.path.join(abspath + "\\startup\\muyuyu.tbr")
with open(path1, "r", encoding='gbk') as f:
lines = f.readlines()
with open(path1, "w") as f_w:
for line in lines:
str1 = re.findall("BITMAP (.*)icon", line)
str2 = re.findall("ACTION (.*)startup", line)
if str1:
line = line.replace(str1[0], abspath + "\\")
if str2:
line = line.replace(str2[0], abspath + "\\")
f_w.write(line)
def gourl(event):
webbrowser.open("www.huangwenyang.cn")
path1 = tkinter.StringVar()
path2 = tkinter.StringVar()
# 标题栏
label1 = tkinter.Label(text="欢迎使用ug插件安装器--hwy")
label1.pack()
# 设置ug选择路径
label2 = tkinter.Label(text="请选择ug安装路径:")
label2.place(x=10, y=50)
entry1 = tkinter.Entry(textvariable=path1)
entry1.place(x=125, y=50)
button1 = tkinter.Button(text="选择路径", command=filepath1)
button1.place(x=280, y=45)
# 操作按钮
button4 = tkinter.Button(text="确定", command=showinfo)
button4.place(x=350, y=160)
button5 = tkinter.Button(text="退出", command=win.quit)
button5.place(x=300, y=160)
# 提示
label3 = tkinter.Label(text="提示:该软件应与startup同目录")
label3.place(x=110, y=110)
label4 = tkinter.Label(text="欢迎访问我的个人网站:www.huangwenyang.cn")
# 绑定事件
label4.bind("<Button-1>", gourl)
label4.place(x=70, y=130)
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,729
|
Mr-big-c/github
|
refs/heads/master
|
/tkinter/label控件.py
|
"""
label: 标签控件,可以显示文本
"""
import tkinter
win = tkinter.Tk()
win.title('黄文杨') # 设置标题
win.geometry('400x400+200+200') # 设置大小和位置
# win选择父窗体 text 显示的文本内容 bg:背景色 fg:字体颜色
label = tkinter.Label(win, text="python",
bg="blue", fg="red", width=20, height=4, wraplength=40, justify="right",
anchor="s")
# 在窗口中显示出来控件
label.pack()
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,730
|
Mr-big-c/github
|
refs/heads/master
|
/tkinter/checkbutton.py
|
'''
多选按钮
'''
import tkinter
win = tkinter.Tk()
win.title("hwy")
win.geometry("400x400")
def update():
messge = ""
if hobby1.get() == True:
messge += "money\n"
if hobby2.get() == True:
messge += "power\n"
if hobby3.get() == True:
messge += "python\n"
# 清空text中的内容
text.delete(0.0, tkinter.END)
text.insert(tkinter.INSERT, messge)
hobby1 = tkinter.BooleanVar()
hobby2 = tkinter.BooleanVar()
hobby3 = tkinter.BooleanVar()
checkbutton1 = tkinter.Checkbutton(win, text="money", variable=hobby1, command=update)
checkbutton2 = tkinter.Checkbutton(win, text="power", variable=hobby2, command=update)
checkbutton3 = tkinter.Checkbutton(win, text="python", variable=hobby3, command=update)
checkbutton1.pack()
checkbutton2.pack()
checkbutton3.pack()
text = tkinter.Text(win, width=40, height=5)
text.pack()
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,731
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-8/myapp/migrations/0002_auto_20180721_1709.py
|
# Generated by Django 2.0 on 2018-07-21 09:09
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('myapp', '0001_initial'),
]
operations = [
migrations.RenameField(
model_name='article',
old_name='file',
new_name='file_upload',
),
]
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,732
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-11/Like/views.py
|
from django.shortcuts import render
from Like.models import LikeAr
from django.contrib.contenttypes.models import ContentType
from django.http import JsonResponse
# Create your views here.
def like_up(request):
data = {}
data['status'] = 'SUCCESS'
data['is_like'] = "ok"
return JsonResponse(data)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,733
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-31/Like/admin.py
|
from django.contrib import admin
from Like.models import LikeCount, LikeRecord
# Register your models here.
class LikeCountAdmin(admin.ModelAdmin):
list_display = ('pk', 'content_object', 'like_num')
class LikeRecordAdmin(admin.ModelAdmin):
list_display = ('pk', 'content_object', 'like_user', 'like_time')
admin.site.register(LikeCount, LikeCountAdmin)
admin.site.register(LikeRecord, LikeRecordAdmin)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,734
|
Mr-big-c/github
|
refs/heads/master
|
/快捷办公/创建word文档.py
|
"""
创建word文档
"""
import win32com
import win32com.client
import os
def makeword(path, name):
# 调用win32的word功能,支持docx和doc两种格式的文件
mw = win32com.client.Dispatch("Word.APPlication")
# 让文档可见
mw.visible = True
# 创建文档
doc = mw.Documents.Add()
# 写内容
# 从头开始写
r = doc.Range(0, 0)
r.InsertAfter("你好" + name + "\n")
r.InsertAfter("-------------很高兴认识你!")
# 存储文件
doc.SaveAs(path)
# 关闭文件
doc.Close()
# 关闭word功能
mw.Quit()
names = ['python', 'java', 'c++']
path = "C:\\Users\\Administrator\\Desktop\\"
for name in names:
newpath = os.path.join(path, name)
makeword(newpath, name)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,735
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog7-27/myapp/views.py
|
from django.shortcuts import render, HttpResponse
from django.core.paginator import Paginator
from .models import *
# Create your views here.
# 显示文章数据
def show_Articles_data(request):
data=Article.objects.all()
# 得到get请求中的页码参数
page_num = request.GET.get('page', 1)
# 实例化一个分页器
paginator = Paginator(data, 5)
# 通过页码获得对应的文章,可以使用paginator.page, 但是这个方法不能对get获得的数据进行筛选,所以使用get_page
article_list = paginator.get_page(page_num)
# 前端页面参数字典
context = {}
context['data'] = article_list.object_list
context['obj'] = article_list
# 判断是否当前页是否是第一页
if int(article_list.number) == 1:
# 总页数超过3页
if (int(article_list.number) + 2) <= paginator.num_pages:
context["page_num"] = range(int(article_list.number), int(article_list.number) + 3)
else:
context["page_num"]=range(int(article_list.number), int(paginator.num_pages) + 1)
# 判断是否是最后一页
elif not article_list.has_next():
if (int(article_list.number) - 2) > 0:
context["page_num"]=range(int(article_list.number) - 2, int(article_list.number) + 1)
else:
context["page_num"]=range(1, int(article_list.number) + 1)
else:
if (int(article_list.number) - 1) > 0 and (int(article_list.number) + 1) <= paginator.num_pages:
context['page_num'] = range(int(article_list.number) - 1, int(article_list.number) + 2)
elif (int(article_list.number) - 1) <= 0 and (int(article_list.number) + 1) <= paginator.num_pages:
context['page_num']=range(1, int(article_list.number) + 2)
else:
context['page_num']=range(1, int(article_list.number) + 1)
return render(request, 'index.html', context)
def content(request):
pk = request.GET.get('pk')
try:
# 通过获得get请求中的数据查询文本内容,根据判断长度来确定是否查找到数据(数据是否存在)
# 存在数据,则在原数据的基础上加1
articles=Article.objects.get(pk=pk)
if Read_Num.objects.filter(article=articles).count():
articles.read_num.read_num_data += 1
articles.read_num.save()
# 不存在数据,创建对象,并且使阅读数设置为0
else:
readnum = Read_Num()
readnum.article = articles
readnum.read_num_data = 1
readnum.save()
text = articles.text
context = {}
context['text'] = text
return render(request, 'content_template.html', context)
except:
return HttpResponse('404')
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,736
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-15/Run/views.py
|
from django.shortcuts import render
from .models import Run
from django.core.paginator import Paginator
# Create your views here.
def run_img_list(request):
run_list = Run.objects.filter(is_delete=False)
# 得到get请求中的页码参数
page_num = request.GET.get('page', 1)
# 实例化一个分页器
paginator = Paginator(run_list, 20)
# 通过页码获得对应的文章,可以使用paginator.page, 但是这个方法不能对get获得的数据进行筛选,所以使用get_page
article_list = paginator.get_page(page_num)
context = {}
context['run_list'] = article_list
context['data'] = article_list.object_list
context['obj'] = article_list
# 判断是否当前页是否是第一页
if int(article_list.number) == 1:
# 总页数超过3页
if (int(article_list.number) + 2) <= paginator.num_pages:
context["page_num"]=range(int(article_list.number), int(article_list.number) + 3)
else:
context["page_num"]=range(int(article_list.number), int(paginator.num_pages) + 1)
# 判断是否是最后一页
elif not article_list.has_next():
if (int(article_list.number) - 2) > 0:
context["page_num"]=range(int(article_list.number) - 2, int(article_list.number) + 1)
else:
context["page_num"]=range(1, int(article_list.number) + 1)
else:
if (int(article_list.number) - 1) > 0 and (int(article_list.number) + 1) <= paginator.num_pages:
context['page_num']=range(int(article_list.number) - 1, int(article_list.number) + 2)
elif (int(article_list.number) - 1) <= 0 and (int(article_list.number) + 1) <= paginator.num_pages:
context['page_num']=range(1, int(article_list.number) + 2)
else:
context['page_num']=range(1, int(article_list.number) + 1)
return render(request, 'run_img_list.html', context)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,737
|
Mr-big-c/github
|
refs/heads/master
|
/Flask/Flask_win/flask_web/blueprint2/views/views.py
|
# -*- coding: utf-8 -*-
# @File : views2.py
# @Author: 一稚杨
# @Date : 2018/6/8/008
# @Desc : 蓝图2
from flask import Blueprint
# 实例化一个蓝图对象
blueprint2 = Blueprint("blueprint3", __name__)
# 通过blueprint2来创建路由
@blueprint2.route("/index2")
def index2():
return "blueprint2"
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,738
|
Mr-big-c/github
|
refs/heads/master
|
/代码中转站/blog/myapp/views.py
|
from django.shortcuts import render
# Create your views here.
from myapp.models import books
def index(request):
# pk = request.GET.get("pk")
# print(pk)
book_data = books.objects.filter(pk=3).values()
print(book_data)
return render(request, "index.html", {'data': book_data[0]})
def blog(request):
pk = request.GET.get("pk")
book_info = books.objects.filter(pk=pk).values()
print(book_info)
return render(request, 'blog.html', {'data': book_info[0]})
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,739
|
Mr-big-c/github
|
refs/heads/master
|
/代码中转站/blog/myapp/migrations/0003_auto_20180619_1030.py
|
# Generated by Django 2.0.6 on 2018-06-19 10:30
import ckeditor.fields
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('myapp', '0002_auto_20180619_0757'),
]
operations = [
migrations.AlterField(
model_name='books',
name='content',
field=ckeditor.fields.RichTextField(),
),
]
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,740
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog7-17/myapp/admin.py
|
from django.contrib import admin
from .models import *
# Register your models here.
# 注册模型Article
class ArticleAdmin(admin.ModelAdmin):
list_display = ('id', 'title', 'author', 'text', 'get_read_num')
admin.site.register(Article, ArticleAdmin)
admin.site.register(Diary, ArticleAdmin)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,741
|
Mr-big-c/github
|
refs/heads/master
|
/练习代码/Flask/6.7/POST_data.py
|
# -*- coding: utf-8 -*-
# @File : POST_data.py.py
# @Author: 一稚杨
# @Date : 2018/6/7/007
# @Desc : 利用post进行数据交互和文件的上传
from flask import Flask, render_template, request, make_response
import os
# 设置文件上传存放的文件夹
FOLDER = "static/uploads"
# 创建一个flask应用
app = Flask(__name__)
# 设置文件的下载路径
app.config["UPLOAD_FOLDER"] = FOLDER
# 创建路由并指定视图函数
@app.route("/post")
def post():
# 通过make——response设置cookie
res = make_response(render_template("post.html"))
# 第一个参数对应于cookie中的key,第二个参数对应于value
res.set_cookie("name", "hwy")
res.set_cookie("age", '22')
return res
@app.route("/get_data/", methods=["GET", "POST"])
def get_data():
# 得到post提交的数据
if request.method == "GET":
data = request.args.get("username")
# 得到请求的方法
method = request.method
# 得到cookie
data = request.form
cookie = request.cookies
print(data)
return render_template("get_data.html", data=data)
# 提交文件
@app.route("/file")
def file():
return render_template("file.html")
# 对提交的文件进行处理
@app.route("/get_filename/", methods=["GET", "POST"])
def filename():
# 验证密码是否正确
password = request.form["password"]
if password == "muyuyu123":
# 验证是否选择了文件
x = request.files.to_dict()
if x == {}:
result = "请选择文件"
else:
# 得到文件
for file in request.files.getlist("filename[]"):
# 得到文件名
filename = file.filename
# 将文件保存到本地
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
result = "上传成功"
else:
result = "密码错误"
return result
# 运行app
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port="80")
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,742
|
Mr-big-c/github
|
refs/heads/master
|
/Flask/Flask_win/6.2/response.py
|
"""
Flask Response对象的使用
"""
from flask import Flask, make_response
# 创建一个Flask应用
app = Flask(__name__)
# 创建一个视图函数
def index():
# 其实return的实质是:将返回的内容交给response这个类去处理
# 最终返回的是response实例化的一个对象,其中有一些参数
# 比如status code(状态码),content type(返回内容的类型)
# 由于返回给前端的内容实质就是response实例化过后的对象,所以我们可以修改response
# 中的内容来控制返回的内容
# 创建headers
headers = {
"Content-Type": "text/plain",
"data": "this is Flask",
}
# 创建Response对象,并指定参数,参数1:返回的内容,参数2:状态码(301表示重定向)
Response = make_response("<html>this is Flask</html>", 200)
# 修改Response对象的headers
Response.headers = headers
return Response
# 创建路由映射表
app.add_url_rule("/index/", view_func=index)
# 开启应用
if __name__ == "__main__":
app.run(host='0.0.0.0',debug=True)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,743
|
Mr-big-c/github
|
refs/heads/master
|
/练习代码/Flask/m68/models/books.py
|
# -*- coding: utf-8 -*-
# @File : views1.py
# @Author: 一稚杨
# @Date : 2018/6/8/008
# @Desc : 创建一个模型类
from sqlalchemy import Column, Integer, String
from flask_sqlalchemy import SQLAlchemy
# 实例化一个SQLAlchemy
db = SQLAlchemy()
# 创建一个模型类,需要继承于db.Model
class book(db.Model):
# 创建对应的数据字段,并指定类型
id = Column(Integer, primary_key=True, autoincrement=True)
title = Column(String(64), nullable=False)
# default表示当对应的数据为空时,默认设置为default的值, unique设置该字段为唯一的
author = Column(String(20), default="一稚杨", unique=True)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,744
|
Mr-big-c/github
|
refs/heads/master
|
/tkinter/frame.py
|
'''
frame控件,作为框架容器使用
'''
import tkinter
win = tkinter.Tk()
win.title("hwy")
win.geometry("400x400")
# 在win下创建一个frame容器
frame = tkinter.Frame(win)
frame.pack()
# 在frame容器的左边创建一个frame1容器
frame_1 = tkinter.Frame(frame)
# 再在frame_1这个容器中创建标签
tkinter.Label(frame_1, text="左上", bg="red").pack(side=tkinter.TOP)
tkinter.Label(frame_1, text="左下", bg="pink").pack(side=tkinter.TOP)
frame_1.pack(side=tkinter.LEFT)
# 在frame容器的左边创建一个frame容器
frame_2 = tkinter.Frame(frame)
# 再在frame_2这个容器中创建标签
tkinter.Label(frame_2, text="右上", bg="yellow").pack(side=tkinter.TOP)
tkinter.Label(frame_2, text="右下", bg="blue").pack(side=tkinter.TOP)
frame_2.pack(side=tkinter.RIGHT)
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,745
|
Mr-big-c/github
|
refs/heads/master
|
/tkinter/menu.py
|
"""
顶层菜单
"""
import tkinter
win = tkinter.Tk()
win.title("hwy")
win.geometry("400x400")
def showinfo():
print('hwy is a good man')
# 创建菜单条
menubar = tkinter.Menu(win)
win.config(menu=menubar)
# 创建菜单选项
menu1 = tkinter.Menu(menubar, tearoff=False)
# 给菜单选项添加内容
for item in ['python', "c++", "C", "PHP", "java", "C#", "quit"]:
if item == "quit":
# 添加分割线
menu1.add_separator()
menu1.add_command(label=item, command=win.quit)
else:
menu1.add_command(label=item, command=showinfo)
# 向菜单条上添加菜单选项
menubar.add_cascade(label="语言", menu=menu1)
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,746
|
Mr-big-c/github
|
refs/heads/master
|
/快捷办公/模拟键盘.py
|
"""
用程序模拟按键盘
"""
import win32api
import win32con
import time
# # 按下键盘
# win32api.keybd_event(91, 0, 0, 0)
# time.sleep(0.1)
# # 抬起按键
# win32api.keybd_event(91, 0, win32con.KEYEVENTF_KEYUP, 0)
while True:
win32api.keybd_event(91, 0, 0, 0)
time.sleep(0.1)
win32api.keybd_event(68, 0, 0, 0)
time.sleep(0.1)
win32api.keybd_event(91, 0, win32con.KEYEVENTF_KEYUP, 0)
win32api.keybd_event(68, 0, win32con.KEYEVENTF_KEYUP, 0)
time.sleep(4)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,747
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-31/myapp/views.py
|
from django.shortcuts import render, HttpResponse, HttpResponseRedirect
from django.core.paginator import Paginator
from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from django.contrib import auth
from .models import *
from .forms import *
from Recent_Read.models import Recent_Read
from django.contrib.contenttypes.models import ContentType
from Comment.models import Comment
from Comment.Form.comment_text_form import CommentText
from django.http import JsonResponse
import random
from django.core.mail import send_mail
# Create your views here.
# Ajax请求错误响应方法
def error_response(message):
data = {}
data['status'] = 'ERROR'
data['message'] = message
return JsonResponse(data)
# Ajax请求成功响应方法
def success_response(previous_page, message):
data = {}
data['status'] = 'SUCCESS'
data['message'] = message
data['previous_page'] = previous_page
return JsonResponse(data)
# 得到评论的数据
def get_comment(content_type, object_id):
content_type = ContentType.objects.get(model=content_type)
comment_status = Comment.objects.filter(content_type=content_type, object_id=object_id).exists()
# 有评论数据
if comment_status:
return Comment.objects.filter(content_type=content_type, object_id=object_id)
# 没有评论数据
else:
return 'None'
# 显示文章数据
def show_Articles_data(request):
data = Article.objects.filter(status='p')
# 得到get请求中的页码参数
page_num = request.GET.get('page', 1)
# 实例化一个分页器
paginator = Paginator(data, 8)
# 通过页码获得对应的文章,可以使用paginator.page, 但是这个方法不能对get获得的数据进行筛选,所以使用get_page
article_list = paginator.get_page(page_num)
# 前端页面参数字典
context = {}
context['data'] = article_list.object_list
context['obj'] = article_list
context['user'] = request.user
# 判断是否当前页是否是第一页
if int(article_list.number) == 1:
# 总页数超过3页
if (int(article_list.number) + 2) <= paginator.num_pages:
context["page_num"] = range(int(article_list.number), int(article_list.number) + 3)
else:
context["page_num"]=range(int(article_list.number), int(paginator.num_pages) + 1)
# 判断是否是最后一页
elif not article_list.has_next():
if (int(article_list.number) - 2) > 0:
context["page_num"]=range(int(article_list.number) - 2, int(article_list.number) + 1)
else:
context["page_num"]=range(1, int(article_list.number) + 1)
else:
if (int(article_list.number) - 1) > 0 and (int(article_list.number) + 1) <= paginator.num_pages:
context['page_num'] = range(int(article_list.number) - 1, int(article_list.number) + 2)
elif (int(article_list.number) - 1) <= 0 and (int(article_list.number) + 1) <= paginator.num_pages:
context['page_num']=range(1, int(article_list.number) + 2)
else:
context['page_num']=range(1, int(article_list.number) + 1)
return render(request, 'index.html', context)
def content(request):
pk = request.GET.get('pk')
# try:
# 通过获得get请求中的数据查询文本内容,根据判断长度来确定是否查找到数据(数据是否存在)
# 存在数据,则在原数据的基础上加1
articles = Article.objects.get(pk=pk)
ct = ContentType.objects.get_for_model(Article)
# 判断用户是否登录,如果已经登录,则实例化一个历史记录并保存生效
if not request.user.is_anonymous:
re = Recent_Read(content_type=ct, object_id=pk,user=request.user)
re.save()
if Read_Num.objects.filter(article=articles).count():
articles.read_num.read_num_data += 1
articles.read_num.save()
# 不存在数据,创建对象,并且使阅读数设置为0
else:
readnum = Read_Num()
readnum.article = articles
readnum.read_num_data = 1
readnum.save()
text = articles.text
context = {}
context['text'] = text
context['pk'] = pk
context['user'] = request.user
context['log_info'] = request.user.is_authenticated
# 得到评论数据
comment_data = get_comment('article', pk)
context['comment_data'] = comment_data
# 得到评论表单
context['comment_form'] = CommentText()
# 得到表态的用户列表
content_type = ContentType.objects.get(model='article')
attitude_list = AttitudeRecord.objects.filter(content_type=content_type, object_id=pk)
attitude_user_list = []
for attitude in attitude_list:
attitude_user_list.append(attitude.attitude_user.username)
# 返回评论用户列表的长度以及具体的用户名
context['attitude_user_list_len'] = len(attitude_user_list)
context['attitude_user_list'] = attitude_user_list
return render(request, 'content_template.html', context)
# except:
return HttpResponse('404')
# 用户登录
def login(request):
if request.method == "GET":
context = {}
context['previous_page'] = request.GET.get('from_page', '/index')
return render(request, 'login.html', context)
else:
username_or_email = request.POST['username_or_email']
password = request.POST['password']
previous_page = request.POST['previous_page']
try:
# 根据用户名判断用户是否存在
user = authenticate(request, username=username_or_email, password=password)
if user is None:
# user为空,说明以username_or_email为用户名不正确,还需要判断username_or_email是否为邮箱
# 假定为邮箱,判断该邮箱是否存在,如果存在则取出其用户名进行判断
if User.objects.filter(email=username_or_email).exists():
username = User.objects.get(email=username_or_email).username
user = authenticate(request, username=username, password=password)
if user is None:
# username_or_email为邮箱时也不成立,说明输入的信息错误
return error_response('用户名或密码错误!')
else:
# username_or_email为邮箱时也不成立,说明输入的信息错误
return error_response('用户名或密码错误!')
# 该用户存在,进行登录
auth.login(request, user)
return success_response(previous_page, '登录成功!')
except:
return error_response('登录过程出现错误,请重新登录!')
# 用户注销
def logout(request):
auth.logout(request)
return HttpResponseRedirect(request.GET.get('from_page', '/index'))
# 用户注册
def register(request):
# GET请求处理方法
if request.method == "GET":
context = {}
# 得到来源页面
context['previous_page'] = request.GET.get('from_page', '/index')
return render(request, 'register.html', context)
# POST请求处理方法
else:
try:
# 得到用户名和密码
username = request.POST['username']
password = request.POST['password']
# 判断两次输入的密码是否一致
if not password == request.POST['again_password']:
return error_response('两次输入的密码不一致!')
# 判断用户名是否存在
if User.objects.filter(username=username).exists():
return error_response('用户名已存在!')
else:
# 判断输入的验证码是否正确
if request.session.get('code') == request.POST['verification_code']:
user = User.objects.create_user(username=username, password=password, email=request.POST['email'])
user.save()
return success_response(request.POST['previous_page'], '注册成功!')
else:
return error_response('验证码错误!')
# 其余错误
except:
return error_response('注册过程异常,请重新注册!')
# 忘记密码对应的处理方法
def forgot_password(request):
if request.method == 'GET':
return render(request, 'forgot_password.html')
else:
# 得到表单中的数据
# 邮箱
email = request.POST['email']
# 验证码
verification_code = request.POST['verification_code']
# 密码
password = request.POST['password']
# 确认密码
again_password = request.POST['again_password']
# 验证验证码是否正确
if not verification_code == request.session.get('code'):
return error_response('验证码错误!')
# 验证码通过,验证两次的密码是否相同
if not password == again_password:
return error_response('两次输入的密码不一致!')
# 验证码和密码全通过,可以重置密码
try:
user = User.objects.get(email=email)
user.set_password(password)
user.save()
# 清除session
request.session.clear()
data = {}
data['status'] = 'SUCCESS'
data['message'] = '密码修改成功'
return JsonResponse(data)
except:
return error_response('修改密码过程出现错误,请重试!')
# 忘记密码的验证码请求方法
def forgot_code(request):
# 得到邮箱
email = request.POST['email']
# 判断邮箱是否存在
if not User.objects.filter(email=email).exists():
return error_response('该邮箱未绑定!')
# 邮箱存在,发送验证码
request.session['code'] = generate_verification_code()
# 发送邮件
send_mail(
# 发送邮件的标题
'黄文杨的个人网站~找回密码验证码~,谢谢使用!',
# 发送邮件的内容
request.session.get('code'),
# 发送者
'2551628690@qq.com',
# 接受者
[email],
# 发送失败是否返回错误信息
fail_silently=False,
)
data = {}
data['status'] = 'SUCCESS_CODE'
return JsonResponse(data)
# 生成验证码请求方法
def get_verification_code(request):
data = {}
# 判断邮箱是否已经注册
if User.objects.filter(email=request.POST['email']).exists():
return error_response('该邮箱已经注册!')
data['status'] = 'SUCCESS'
# 得到随机的四位验证码
request.session['code'] = generate_verification_code()
# 发送邮件
send_mail(
# 发送邮件的标题
'黄文杨的个人网站~验证码~,谢谢使用!',
# 发送邮件的内容
request.session.get('code'),
# 发送者
'2551628690@qq.com',
# 接受者
[request.POST['email']],
# 发送失败是否返回错误信息
fail_silently=False,
)
return JsonResponse(data)
# 得到四位随机验证码
def generate_verification_code():
code_list = []
for i in range(2):
random_num = random.randint(0, 9)
a = random.randint(97, 122)
random_uppercase_letter = chr(a)
code_list.append(str(random_num))
code_list.append(random_uppercase_letter)
verification_code = ''.join(code_list)
return verification_code
# Django form表单测试
def loginform(request):
if request.method == 'POST':
login_form = LoginForm(request.POST)
# 判断接受的数据是否有效,有效则为True,否则为FALSE(比如输入的是一串空格)
if login_form.is_valid():
user = login_form.cleaned_data['user']
auth.login(request, user)
return HttpResponseRedirect(request.GET.get('from_page'))
else:
# 实例化一个Form表单对象
login_form = LoginForm()
context = {}
# 传递给模板文件
context['login_form'] = login_form
return render(request, 'test.html', context)
# 测试用视图函数
def test(request):
user = request.user
print(request.session.get('code'))
print(user.is_anonymous)
return HttpResponse('test')
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,748
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog7-21/myapp/views.py
|
from django.shortcuts import render, HttpResponse
from .models import *
# Create your views here.
# 显示文章数据
def show_Articles_data(request):
data = Article.objects.all()
context = {}
context['data'] = data
return render(request, 'index.html', context)
def content(request):
pk = request.GET.get('pk')
try:
# 通过获得get请求中的数据查询文本内容,根据判断长度来确定是否查找到数据(数据是否存在)
# 存在数据,则在原数据的基础上加1
articles=Article.objects.get(pk=pk)
if Read_Num.objects.filter(article=articles).count():
articles.read_num.read_num_data += 1
articles.read_num.save()
# 不存在数据,创建对象,并且使阅读数设置为0
else:
readnum = Read_Num()
readnum.article = articles
readnum.read_num_data = 1
readnum.save()
text = articles.text
context = {}
context['text'] = text
return render(request, 'content_template.html', context)
except:
return HttpResponse('404')
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,749
|
Mr-big-c/github
|
refs/heads/master
|
/快捷办公/csv文件操作/读csv文件.py
|
"""
读取csv文件中的数据
"""
import csv
def readcsv(path):
# 以只读模式打开path路径所指的文件
with open(path, "r") as f:
# 用csv中的reader方法打开文件,获得的是一个对象
alldata = csv.reader(f)
datalist = []
for row in alldata:
datalist.append(row)
return datalist
path = r"D:\Python数据\csv数据.csv"
result = readcsv(path)
print(result)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,750
|
Mr-big-c/github
|
refs/heads/master
|
/tkinter/树状结构.py
|
"""
实现树状的结构,类似文件夹的结构
"""
import tkinter
from tkinter import ttk
win = tkinter.Tk()
win.title("hwy")
win.geometry("400x400")
tree = ttk.Treeview(win)
tree.pack()
# 创建一级菜单
tree1 = tree.insert("", 0, "成都", text="成都")
tree2 = tree.insert("", 1, "自贡", text="自贡")
tree3 = tree.insert("", 2, "上海", text="上海")
# 创建二级菜单
tree1_1 = tree.insert(tree1, 0, "郫县", text="郫县")
tree1_2 = tree.insert(tree1, 1, "武侯", text="武侯")
tree1_3 = tree.insert(tree1, 2, "金牛", text="金牛")
tree2_1 = tree.insert(tree2, 0, "富顺", text="富顺")
tree2_2 = tree.insert(tree2, 1, "12", text="12")
tree2_3 = tree.insert(tree2, 2, "23", text="23")
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,751
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog7-17/myapp/views.py
|
from django.shortcuts import render, HttpResponse
from .models import *
# Create your views here.
# 显示文章数据
def show_Articles_data(request):
data = Article.objects.all()
context = {}
context['data'] = data
return render(request, 'index.html', context)
# 显示具体内容
def content(request):
pk = request.GET.get('pk')
article = Article.objects.get(pk=pk)
# 得到一个可以实例化ReadNum的模型类
ct=ContentType.objects.get_for_model(Article)
try:
# 查询数据库
re=ReadNum.objects.get(content_type=ct, object_id=pk)
# 阅读数量加1
re.read_num += 1
re.save()
except:
# 没有数据,实例化一个对象,并将阅读数量设置为1
re = ReadNum(content_type=ct, object_id=pk, read_num=1)
re.save()
context = {}
context['blog'] = article
return render(request, 'content_template.html', context)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,752
|
Mr-big-c/github
|
refs/heads/master
|
/Flask/Flask_win/6.2/config.py
|
"""
Flask项目的配置文件
"""
DEBUG = True
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,753
|
Mr-big-c/github
|
refs/heads/master
|
/实战项目/直线插补/源码.py
|
"""
逐点比较法--直线插补
"""
# -- coding:utf-8 --
import matplotlib.pyplot as plt
import tkinter
# 定义直线函数
def function(x, y):
xo = x[0]
xe = x[1]
yo = y[0]
ye = y[1]
# 得到斜率
k = (ye - yo)/(xe - xo)
# 得到b
b = ye - k*xe
return (k, b)
def is_ok(xo, yo, k, b):
num = k*xo + b - yo
# 设置精度
a = int(entry5.get())
num = round(num, a)
if k >= 0:
if float(entry2.get()) >= 0:
if num <= 0:
return 1
else:
return 0
else:
if num >= 0:
return 1
else:
return 0
else:
if float(entry2.get()) >= 0:
if num >= 0:
return 1
else:
return 0
else:
if num <= 0:
return 1
else:
return 0
# 插补函数
def runin(result, xo, yo, k, p):
if k >= 0:
if result == 1:
if float(entry2.get()) >= 0:
xo = xo + p
yo = yo
else:
xo = xo - p
yo = yo
else:
if float(entry2.get()) >= 0:
yo = yo + p
xo = xo
else:
yo = yo - p
xo = xo
result = (xo, yo)
return result
else:
if result == 1:
if float(entry2.get()) >= 0:
xo = xo + p
yo = yo
else:
xo = xo - p
yo = yo
else:
if float(entry2.get()) >= 0:
yo = yo - p
xo = xo
else:
yo = yo + p
xo = xo
result = (xo, yo)
return result
# 画出图形
def show():
plt.figure()
plt.title(u"line")
# print("起点:" + "\n")
xo = float(entry.get())
yo = float(entry1.get())
# print("终点" + "\n")
xe = float(entry2.get())
ye = float(entry3.get())
p = float(entry4.get())
x = (xo, xe)
y = (yo, ye)
result1 = function(x, y)
k = result1[0]
b = result1[1]
number = int(abs(xe - xo) + abs(ye - yo))
plt.axis("equal")
plt.plot(x, y)
txt.insert(tkinter.INSERT, "(" + str(xo) + "," + str(yo) + ")" + "\n")
for i in range(int(number/p)):
# print(i)
# print(xo, yo)
result3 = is_ok(xo, yo, k, b)
# print(result3)
result2 = runin(result3, xo, yo, k, p) # 终点
plot_end = result2
plt.pause(0.5)
plt.plot((xo, plot_end[0]), (yo, plot_end[1]))
xo = plot_end[0]
yo = plot_end[1]
txt.insert(tkinter.INSERT, "(" + str(xo) + "," + str(yo) + ")" + "\n")
plt.show()
# 清除数据
def clear():
txt.delete(0.0, tkinter.END)
win = tkinter.Tk()
win.title("hwy")
win.geometry("600x400")
win.resizable(width=False, height=False)
label1 = tkinter.Label(win, text="直线插补")
label1.pack()
label2 = tkinter.Label(win, text="起点坐标:Xo=")
label2.place(x=100, y=100)
e = tkinter.Variable()
entry = tkinter.Entry(win, textvariable=e)
e.set(0)
entry.place(x=200, y=100)
label3 = tkinter.Label(win, text="起点坐标:Yo=")
label3.place(x=100, y=130)
e1 = tkinter.Variable()
entry1 = tkinter.Entry(win, textvariable=e1)
e1.set(0)
entry1.place(x=200, y=130)
label4 = tkinter.Label(win, text="终点坐标:Xe=")
label4.place(x=100, y=160)
e2 = tkinter.Variable()
entry2 = tkinter.Entry(win, textvariable=e2)
e2.set(10)
entry2.place(x=200, y=160)
label5 = tkinter.Label(win, text="终点坐标:Ye=")
label5.place(x=100, y=190)
e3 = tkinter.Variable()
entry3 = tkinter.Entry(win, textvariable=e3)
e3.set(10)
entry3.place(x=200, y=190)
label6 = tkinter.Label(win, text="脉冲当量:P=")
label6.place(x=100, y=220)
e4 = tkinter.Variable()
entry4 = tkinter.Entry(win, textvariable=e4)
e4.set(1)
entry4.place(x=200, y=220)
label7 = tkinter.Label(win, text="精度:A=")
label7.place(x=100, y=250)
e5 = tkinter.Variable()
entry5 = tkinter.Entry(win, textvariable=e5)
e5.set(5)
entry5.place(x=200, y=250)
# 显示坐标值
txt = tkinter.Text(win)
txt.place(x=400, y=30)
button = tkinter.Button(win, text="插补计算", command=show)
button.place(x=250, y=350)
button1 = tkinter.Button(win, text="清除坐标", command=clear)
button1.place(x=340, y=350)
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,754
|
Mr-big-c/github
|
refs/heads/master
|
/tkinter/menu鼠标右键.py
|
"""
鼠标右键菜单
"""
import tkinter
win = tkinter.Tk()
win.title("hwy")
win.geometry("400x400")
# 创建菜单条
menubar = tkinter.Menu(win)
# 创建菜单选项
menu1 = tkinter.Menu(menubar, tearoff=False)
# 给菜单选项添加内容
for item in ['python', "c++", "C", "PHP", "java", "C#", "quit"]:
if item == "quit":
# 添加分割线
menu1.add_separator()
menu1.add_command(label=item, command=win.quit)
else:
menu1.add_command(label=item)
# 向菜单条上添加菜单选项
menubar.add_cascade(label="语言", menu=menu1)
# 以上只是创建了菜单,但是并没有显示,下面就通过鼠标右键这个事件来显示菜单
def showmenu(event):
menubar.post(event.x_root, event.y_root)
win.bind('<Button-3>', showmenu)
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,755
|
Mr-big-c/github
|
refs/heads/master
|
/练习代码/spider5.15/设置超时.py
|
import urllib.request
url = r"http://www.huangwenyang.cn/"
for i in range(50):
try:
req = urllib.request.urlopen(url, timeout=0.01)
print("----------------")
except:
print("请求超时!")
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,756
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-20/Attitude/apps.py
|
from django.apps import AppConfig
class AttitudeConfig(AppConfig):
name = 'Attitude'
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,757
|
Mr-big-c/github
|
refs/heads/master
|
/练习代码/spider5.15/千库网.py
|
import urllib.request
import re
import os
def spider(url):
headers = {
"User-Agent": "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.50"
}
# 创建请求体
req = urllib.request.Request(url, headers=headers)
# 发起请求
response = urllib.request.urlopen(req)
html_data = response.read().decode("utf-8")
return html_data
url = "http://588ku.com/sucai/0-pxnum-0-0-0-1/?h=360&sem=1"
result = spider(url)
re_str = r'data-original="([\s\S]*?)!/fw/254/quality/90/unsharp/true/compress/true"'
img_url_str = re.findall(re_str, result)
img_path = r"C:\Users\Administrator\Desktop\img"
num = 1
for img_url in img_url_str:
# 拼接路径
img_name = os.path.join(img_path, str(num) + ".jpg")
num += 1
# 通过url下载对应的图片并保存到本地
urllib.request.urlretrieve(img_url, filename=img_name)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,758
|
Mr-big-c/github
|
refs/heads/master
|
/快捷办公/list,tuple,dict文件的读写.py
|
import pickle
path = r"C:\Users\Administrator\Desktop\3.txt"
data = [1, 2, 3, 4, "abc"]
f = open(path, "wb")
pickle.dump(data, f)
f.close()
f1 = open(path, "rb")
getdata = pickle.load(f1)
print(getdata)
print(type(getdata))
f1.close()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,759
|
Mr-big-c/github
|
refs/heads/master
|
/tkinter/radiobutton.py
|
'''
单选框控件
'''
import tkinter
win = tkinter.Tk()
win.title("hwy")
win.geometry("400x400")
def showinfo():
print(r.get())
r = tkinter.IntVar()
redio1 = tkinter.Radiobutton(win, text="one", value=11, variable=r, command=showinfo)
redio1.pack()
radio2 = tkinter.Radiobutton(win, text="two", value=22, variable=r, command=showinfo)
radio2.pack()
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,760
|
Mr-big-c/github
|
refs/heads/master
|
/Flask/Flask_win/flask_web/run_app.py
|
# -*- coding: utf-8 -*-
# @File : run_app.py
# @Author: 一稚杨
# @Date : 2018/6/8/008
# @Desc : 引入create_app方法创建一个app并运行
import sys
sys.path.append(r'C:\Users\Administrator\Desktop\Flask')
from flask_web import create_app
from flask import request, render_template
app = create_app()
@app.route("/CSS")
def CSS():
return render_template("CSS背景.html")
if __name__ == "__main__":
app.run(debug=app.config["DEBUG"], host='0.0.0.0', port=8000)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,761
|
Mr-big-c/github
|
refs/heads/master
|
/练习代码/Flask/flask_web/blueprint1/views/views1.py
|
# -*- coding: utf-8 -*-
# @File : views1.py
# @Author: 一稚杨
# @Date : 2018/6/8/008
# @Desc : 创建另一个视图函数,与views共享一个蓝图
from . import blueprint
from flask import render_template
@blueprint.route("/index3")
def index3():
return render_template("data_get.html")
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,762
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/files_system/basics/file_op.py
|
import os
# 删除文件
def file_rm(file_path):
if file_path == '':
return 'file_path error'
try:
# 将文件备份到回收站
cp = os.system('cp ' + file_path + ' /Users/hwy/Desktop/回收站')
# 备份完成后再删除
re = os.system('rm ' + file_path)
if re != 0:
return 'rm error'
else:
return 'rm success'
except:
return 'rm error'
# 删除文件夹
def dir_rm(file_path):
if file_path == '':
return 'file_path error'
try:
# 将文件夹备份到回收站
cp = os.system('cp -r ' + file_path + ' /Users/hwy/Desktop/回收站')
re = os.system('rm -r ' + file_path)
if re != 0:
return 'rm error'
else:
return 'rm success'
except:
return 'rm error'
# 新建文件夹
def mkdir_file(file_path):
if file_path == '':
return 'file_path error'
try:
re = os.system('mkdir ' + file_path)
if re != 0:
return 'mkdir error'
else:
return 'mkdir success'
except:
return 'mkdir error'
# 重命名文件
def rename(file_path, name, new_name):
if file_path == '':
return 'file_path error'
try:
re = os.system('mv ' + file_path + name + ' ' + file_path + new_name)
if re != 0:
return 'rename error'
else:
return 'rename success'
except:
return 'rename error'
# 重命名文件夹
def rename_dir(file_path, name, new_name):
if file_path == '':
return 'file_path error'
try:
re = os.system('mv ' + file_path + name + ' ' + file_path + new_name)
if re != 0:
return 'rename error'
else:
return 'rename success'
except:
return 'rename error'
# 解压文件
def unzip(file_path, sub_path):
if file_path == '' or sub_path == '':
return 'file_path or sub_path reeor'
try:
re = os.system('unrar x ' + file_path + ' ' + sub_path + ' -y')
if re != 0:
return 'unzip error'
else:
return 'unzip success'
except:
return 'unzip error'
# 对文件夹进行压缩
def rar(sub_path, file_name, new_name):
if sub_path == '':
return 'file path error'
try:
print('rar a ' + sub_path + new_name + ' ' + sub_path + file_name)
re = os.system('rar a ' + sub_path + new_name + ' ' + sub_path + file_name)
if re != 0:
return 'rar error'
else:
return 'rar success'
except:
return 'rar error'
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,763
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-15/Attitude/migrations/0002_auto_20180815_2004.py
|
# Generated by Django 2.0 on 2018-08-15 12:04
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('Attitude', '0001_initial'),
]
operations = [
migrations.RenameField(
model_name='attitudecount',
old_name='attitude_applause_num',
new_name='attitude_flower_num',
),
]
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,764
|
Mr-big-c/github
|
refs/heads/master
|
/Flask/Flask_win/flask_web/blueprint1/views/views2.py
|
# -*- coding: utf-8 -*-
# @File : views2.py
# @Author: 一稚杨
# @Date : 2018/6/8/008
# @Desc : 利用蓝图(flask_web)机制分离视图函数与app应用
# 蓝图相当于一个中间机制,它可以间接联系app应用于视图函数,当我们将蓝图与app进行关联过后,这是关键
# 就可以通过蓝图来注册视图函数,而且还可以创建多个蓝图,每个蓝图对应不同的视图类别,而且每个蓝图可以
# 拥有不同的静态文件和模板
# from flask import Blueprint
#
# # 实例化一个蓝图对象
# # 第一个参数是蓝图的名称,第二个参数是蓝图所在的包或者模块,通常使用__name__
# blueprint1 = Blueprint("blueprint1", __name__)
# 这里不再使用单独创建一个蓝图,而是使用一个共享的蓝图,共享蓝图在__init__.py中定义
from . import blueprint
from flask import request, render_template
from flask_web.forms.data_forms import data_forms
# 通过blueprint这个实例化的蓝图对象来创建路由
@blueprint.route("/index/")
def index():
# 实例化一个数据验证对象
data_form = data_forms(request.args)
# 启用验证
if True:
data = {"name": data_form.name.data.strip(), "age": data_form.age.data}
return render_template("CSS背景.html", data=data)
else:
data = data_form.errors
print(data)
return "error"
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,765
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-31/Attitude/templatetags/get_attitude_num.py
|
# -*- coding: utf-8 -*-
# @File : get_attitude_num.py
# @Author: 一稚杨
# @Date : 2018/8/15/015
# @Desc :
from Attitude.models import AttitudeCount, AttitudeRecord
from django import template
from django.contrib.contenttypes.models import ContentType
register = template.Library()
# 对表态数据进行判断,如果表态数量大于5则返回5,以限制表态的高度
def limit_attitude_data(attitude_type, attitude_num):
if attitude_type == 'flower':
if attitude_num.attitude_flower_num <= 5:
return attitude_num.attitude_flower_num
else:
return 5
elif attitude_type == 'handshake':
if attitude_num.attitude_handshake_num <= 5:
return attitude_num.attitude_handshake_num
else:
return 5
elif attitude_type == 'pass':
if attitude_num.attitude_pass_num <= 5:
return attitude_num.attitude_pass_num
else:
return 5
elif attitude_type == 'shocking':
if attitude_num.attitude_shocking_num <= 5:
return attitude_num.attitude_shocking_num
else:
return 5
elif attitude_type == 'egg':
if attitude_num.attitude_egg_num <= 5:
return attitude_num.attitude_egg_num
else:
return 5
else:
return 0
# 得到文章的表态的数据,用于表态数据的显示
@register.simple_tag
def get_attitude_num(content_type, object_id, attitude_type):
content_type = ContentType.objects.get(model=content_type)
attitude_num, create = AttitudeCount.objects.get_or_create(content_type=content_type, object_id=object_id)
return {
'flower': attitude_num.attitude_flower_num,
'handshake': attitude_num.attitude_handshake_num,
'pass': attitude_num.attitude_pass_num,
'shocking': attitude_num.attitude_shocking_num,
'egg': attitude_num.attitude_egg_num,
}.get(attitude_type, 'error')
# 得到文章的表态的数据,用于表态数据的高度显示
@register.simple_tag
def get_attitude_num_height(content_type, object_id, attitude_type):
content_type = ContentType.objects.get(model=content_type)
attitude_num, create = AttitudeCount.objects.get_or_create(content_type=content_type, object_id=object_id)
return {
'flower': limit_attitude_data('flower', attitude_num),
'handshake': limit_attitude_data('handshake', attitude_num),
'pass': limit_attitude_data('pass', attitude_num),
'shocking': limit_attitude_data('shocking', attitude_num),
'egg': limit_attitude_data('egg', attitude_num),
}.get(attitude_type, 'error')
# 判断当前用户对当前文章是否点赞
@register.simple_tag
def get_attitude_record(content_type, object_id, user, attitude_type):
# 判断是否登录,没有登录直接返回空
if not user.is_authenticated:
return ''
content_type = ContentType.objects.get(model=content_type)
if AttitudeRecord.objects.filter(content_type=content_type, object_id=object_id, attitude_user=user, attitude_type=attitude_type).exists():
# 存在点赞记录, 返回active
return 'active'
else:
return ''
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,766
|
Mr-big-c/github
|
refs/heads/master
|
/tkinter/相对布局.py
|
"""
相对布局
"""
import tkinter
win = tkinter.Tk()
win.title("hwy")
win.geometry("400x400")
# 创建三个标签
label1 = tkinter.Label(win, text="python", bg="blue")
label2 = tkinter.Label(win, text="java", bg="red")
label3 = tkinter.Label(win, text="C++", bg="pink")
# fill=tkinter.Y 指定填充方法为Y,side=tkinter.RIGHT 指定放置的位置为靠右
label1.pack(fill=tkinter.Y, side=tkinter.RIGHT)
label2.pack(fill=tkinter.X, side=tkinter.TOP)
label3.pack()
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,767
|
Mr-big-c/github
|
refs/heads/master
|
/tkinter/表格数据.py
|
"""
显示表格数据
"""
import tkinter
from tkinter import ttk
win = tkinter.Tk()
win.title("hwy")
win.geometry("600x400")
# 创建表格
tree = ttk.Treeview(win)
tree.pack()
# 创建列
tree["columns"] = ("姓名", "年龄", "身高", "体重")
# 设置列,只是设置了属性,但是还是不能显示
tree.column("姓名", width=100)
tree.column("年龄", width=100)
tree.column("身高", width=100)
tree.column("体重", width=100)
# 设置表头,这里才设置显示的内容
tree.heading('姓名', text='-姓名-')
tree.heading('年龄', text='-年龄-')
tree.heading('身高', text='-身高-')
tree.heading('体重', text='-体重-')
# 添加数据
tree.insert('', 0, text='1', value=('python', '18', '20', '30'))
tree.insert('', 1, text='2', value=('java', '18', '20', '30'))
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,768
|
Mr-big-c/github
|
refs/heads/master
|
/tkinter/test1.py
|
"""
点击按钮显示输入框的内容
"""
import tkinter
def showinfo():
print(entry.get())
win = tkinter.Tk()
win.title('python')
win.geometry("400x400+400+200")
entry = tkinter.Entry(win, show="#")
entry.pack()
button = tkinter.Button(win, text="按钮", command=showinfo)
button.pack()
button2 = tkinter.Button(win, text="quit", command=win.quit)
button2.pack()
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,769
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-31/Attitude/views.py
|
from django.shortcuts import render
from django.http import JsonResponse
from .models import AttitudeRecord, AttitudeCount
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User
# Create your views here.
# 数据操作成功返回数据方法
def success_response(attitude_type, attitude_num):
data = {}
data['status'] = 'SUCCESS'
if attitude_num > 5:
data['attitude_num'] = 6
else:
data['attitude_num'] = attitude_num
data['attitude_type'] = attitude_type
return JsonResponse(data)
# 数据操作失败返回信息的方法
def error_response(message):
data = {}
data['status'] = 'ERROR'
data['message'] = message
return JsonResponse(data)
# 返回提示信息
def message_response(message):
data = {}
data['status'] = 'message'
data['message'] = message
return JsonResponse(data)
# 自定义的switch方法
def add_attitude_num(attitude_type, attitude_count):
print(attitude_type)
if attitude_type == 'flower':
attitude_count.attitude_flower_num += 1
attitude_count.save()
return attitude_count.attitude_flower_num
elif attitude_type == 'handshake':
attitude_count.attitude_handshake_num += 1
attitude_count.save()
return attitude_count.attitude_handshake_num
elif attitude_type == 'shocking':
attitude_count.attitude_shocking_num += 1
attitude_count.save()
return attitude_count.attitude_shocking_num
elif attitude_type == 'pass':
attitude_count.attitude_pass_num += 1
attitude_count.save()
return attitude_count.attitude_pass_num
elif attitude_type == 'egg':
attitude_count.attitude_egg_num += 1
attitude_count.save()
return attitude_count.attitude_egg_num
else:
return error_response('数据错误')
def get_attitude(request):
# 得到GET请求发送过来的数据
attitude_type = request.GET.get('attitude_type')
if not attitude_type in ('flower', 'handshake', 'shocking', 'pass', 'egg'):
return error_response('只能发表鲜花、握手、路过、雷人、鸡蛋态度')
user = request.user
if not user.is_authenticated:
return error_response('未登录,不能发表态度')
content_type = request.GET.get('content_type')
content_type = ContentType.objects.get(model=content_type)
object_id = request.GET.get('object_id')
# 如果对该篇文章已经表过态了则不能进行表态
if AttitudeRecord.objects.filter(attitude_user=user, content_type=content_type, object_id=object_id).exists():
return message_response('你已经表过态了')
attitude_record, create = AttitudeRecord.objects.get_or_create(content_type=content_type, object_id=object_id, attitude_type=attitude_type, attitude_user=user)
if create:
# 该用户对该文章还没有表过态,创建对应的数据
attitude_count, create = AttitudeCount.objects.get_or_create(content_type=content_type, object_id=object_id)
attitude_num = add_attitude_num(attitude_type, attitude_count)
return success_response(attitude_type, attitude_num)
else:
return message_response('你已经表过态了')
return success_response()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,770
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-8/Run/apps.py
|
from django.apps import AppConfig
class RunConfig(AppConfig):
name = 'Run'
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,771
|
Mr-big-c/github
|
refs/heads/master
|
/Flask/Flask_Mac/settings/create_app.py
|
"""
创建app并初始化
"""
from flask import Flask
from settings import config
def create_app():
# 在创建核心应用是指出静态文件和模板文件的位置,即为app指定了寻找的路径其中 template_folder指定
# 模板文件的路径, static_folder指定静态文件的路径,还可以使用static_path_url指定加载静态文件的url
app = Flask(__name__, template_folder='../blueprint1/templates', static_folder='../blueprint1/static')
app.config.from_object(config)
# 注册蓝图
print("~~~~~~~~~~~~~~~")
print(__name__)
print("~~~~~~~~~~~~~~~")
register_blueprint(app)
return app
def register_blueprint(app):
from blueprint1.views1 import blueprint1
app.register_blueprint(blueprint1)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,772
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog7-21/myapp/models.py
|
from django.db import models
# Create your models here.
# 创建一个文章的模型
class Article(models.Model):
title = models.CharField(max_length=20)
author = models.CharField(max_length=10)
text = models.CharField(max_length=200)
# 图片上传
img = models.ImageField(upload_to='image')
# 文件上传
file_upload = models.FileField(upload_to='file')
def readnum(self):
try:
self.read_num_data = self.read_num.read_num_data
return self.read_num_data
except:
return 0
# 创建一个记录阅读数量的模型
class Read_Num(models.Model):
read_num_data = models.IntegerField()
article = models.OneToOneField('Article', on_delete=models.DO_NOTHING)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,773
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog7-17/myapp/models.py
|
from django.db import models
from django.contrib.contenttypes.models import ContentType
from ReadNumber.models import *
from ckeditor_uploader.fields import RichTextUploadingField
# Create your models here.
# 创建一个文章的模型
class Article(models.Model):
title = models.CharField(max_length=20)
author = models.CharField(max_length=10)
text = RichTextUploadingField(default='<h3>类别</h3><h4>标题</h4><hr /> \
<h4>概要</h4> <ul><li>概要内容</li></ul><h4>小标题1</h4><ul><li>小标题1内容</li></ul>')
def get_read_num(self):
try:
ct = ContentType.objects.get_for_model(Article)
re = ReadNum.objects.filter(content_type=ct, object_id=self.pk)
return re[0].read_num
except:
return 0
class Diary(models.Model):
title=models.CharField(max_length=20)
author=models.CharField(max_length=10)
text=RichTextUploadingField()
def get_read_num(self):
try:
ct = ContentType.objects.get_for_model(Diary)
re = ReadNum.objects.filter(content_type=ct, object_id=self.pk)
return re[0].read_num
except:
return 0
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,774
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-31/Send_Email/views.py
|
from django.shortcuts import render, HttpResponse
from django.core.mail import send_mail
# Create your views here.
def send(request):
send_mail(
# 发送邮件的标题
'黄文杨的个人网站,谢谢使用!',
# 发送邮件的内容
'Here is the message.',
# 发送者
'2551628690@qq.com',
# 接受者
['1838531437@qq.com', '442276457@qq.com'],
# 发送失败是否返回错误信息
fail_silently=False,
)
return HttpResponse('发送成功')
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,775
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/files_system/files_system/urls.py
|
"""files_system URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from basics.views import index, open_folder, download, content, jump, rm_file, rm_file_ajax, mkdir, go_back, file_rename, test, upload, upload_success, file_unzip, file_rar, login, Load
urlpatterns = [
path('admin/', admin.site.urls),
path('', index),
path('open_folder/', open_folder),
path('download/', download),
path('content/', content),
path('jump/', jump),
path('rm_file/', rm_file),
path('rm_file_ajax', rm_file_ajax),
path('mkdir/', mkdir),
path('go_back/', go_back),
path('file_rename/', file_rename),
path('test/', test),
path('upload/', upload),
path('upload/success/', upload_success),
path('file_unzip/', file_unzip),
path('file_rar/', file_rar),
path('login/', login),
path('Load/', Load),
]
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,776
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-31/myapp/forms.py
|
# -*- coding: utf-8 -*-
# @File : forms.py
# @Author: 一稚杨
# @Date : 2018/7/29/029
# @Desc :
from django import forms
from django.contrib import auth
class LoginForm(forms.Form):
# 其中attrs为指定对应字段的前端样式,相当于html表单中的class指定样式
username = forms.CharField(label='用户名', widget=forms.TextInput(attrs={'class': 'form-control'}))
password = forms.CharField(label='密码', widget=forms.PasswordInput(attrs={'class': 'form-control'}))
# 定义clean方法,该方法是Django Form中特定的方法,只要一执行is_valid这个数据检查方法,就会执行clean这个方法
# 所以用户验证的内容可以放在这个方法里面,验证时只需要验证is_valid通过,则表示用户信息没有问题,可以直接登录
def clean(self):
username = self.cleaned_data['username']
password = self.cleaned_data['password']
user = auth.authenticate(username=username, password=password)
# 判断用户信息
if user is None:
# 用户信息错误,返回错误提示信息
raise forms.ValidationError('用户名或密码错误!')
else:
# 用户信息正确
self.cleaned_data['user'] = user
return self.cleaned_data
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,777
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-8/Ajax/views.py
|
from django.shortcuts import render, HttpResponse
from django.http import JsonResponse
# Create your views here.
def ajax(request):
return render(request, 'Ajax.html')
def ajax_form(request):
data = {}
data['status'] = 'SUCCESS'
data['log_info'] = request.POST['username']
return JsonResponse(data)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,778
|
Mr-big-c/github
|
refs/heads/master
|
/练习代码/微信公众号/spider_qqmusic1.py
|
# -*-coding:utf-8-*-
# encoding =utf-8
import requests
import json
from time import time
# 利用时间戳创建guid参数
guid = str(int(time()))
# 创建请求头,必须要保证整个过程的guid的值要相同
hea = {
"User_Agent": r"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Firefox/60.0",
"cookie": 'pgv_pvi=9563846656; pgv_si=s4264375296; pgv_pvid=%s; qqmusic_fromtag=66' % guid,
"Referer": "https://y.qq.com/n/yqq/song/003vUjJp3QwFcd.html",
"Host": "c.y.qq.com"
}
# 得到歌曲id
def spider1(url):
# 发起请求
response = requests.get(url, headers=hea)
# 转化为json数据,提取得到歌曲id
data_list = json.loads(response.text[34:-1])['data']['song']['list']
music_id = data_list[0]["id"]
mid = data_list[0]["mid"]
# 返回id和mid,后面发起请求是要用到这两个参数
return (music_id, mid)
# 得到歌曲的歌词信息
def spider2(music_id):
url = r"https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric.fcg?nobase64=1"
url += "&musicid=" + str(music_id) + r"&callback=jsonp1&g_tk=5381&jsonpCall\
back=jsonp1&loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-\
8¬ice=0&platform=yqq&needNewCode=0"
response = requests.get(url, headers=hea)
print(response.text)
# 得到vkey
def spider3(mid):
url = "https://c.y.qq.com/base/fcgi-bin/fcg_music_express_mobile3.fcg?\
g_tk=5381&jsonpCallback=MusicJsonCallback93443074145225121&loginUin=0&h\
ostUin=0&format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=y\
qq&needNewCode=0&cid=205361747&callback=MusicJsonCallback9344307414522512&\
uin=0&songmid=%s&filename=C400%s.m4a&guid=%s" % (mid, mid, guid)
response = requests.get(url)
data = response.text[34:-1]
vkey = json.loads(data)["data"]["items"][0]["vkey"]
filename = json.loads(data)["data"]["items"][0]["filename"]
return (vkey, filename)
music_keword = input("keyword:")
print(music_keword)
print(type(music_keword))
url = "https://c.y.qq.com/soso/fcgi-bin/client_search_cp?ct=24&\
qqmusic_ver=1298&new_json=1&remoteplace=txt.yqq.song&searchid=57\
319834734357796&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p\
=1&n=20&w=%s&g_tk=5381&jsonpCallback=MusicJsonCallback799849464782\
1491&loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=ut\
f-8¬ice=0&platform=yqq&needNewCode=0" % (music_keword)
id_list = spider1(url)
spider2(id_list[0])
data = spider3(id_list[1])
# 拼接数据得到音乐的播放url
music_url = "http://dl.stream.qqmusic.qq.com/%s?vkey=%s&guid=%s&uin=0&fromtag=66" % (data[1], data[0], guid)
print(music_url)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,779
|
Mr-big-c/github
|
refs/heads/master
|
/tkinter/spinbox.py
|
"""
数值范围控件,可以通过操作改变数值
"""
import tkinter
win = tkinter.Tk()
win.title("hwy")
win.geometry("400x400")
def updata():
print(v.get())
v = tkinter.StringVar()
# from_ 指定起始值,to指定结束值,increment相当于指定分辨率,
# value 指定显示的值,一般不与上面的参数同时使用
spinbox = tkinter.Spinbox(win, from_=0, to=10, increment=2, textvariable=v, command=updata)
v.set(4)
spinbox.pack()
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,780
|
Mr-big-c/github
|
refs/heads/master
|
/练习代码/微信公众号/face.py
|
import requests
import base64
import json
import time
def face(imgurl):
# 通过imgurl对图片进行base64编码
img_content = requests.get(imgurl).content
img_base = base64.b64encode(img_content)
# 将进过编码的图片post给微软服务器
ms_url1 = r"https://kan.msxiaobing.com/Api/Image/UploadBase64"
# 获得图片在微软服务器的url
img_ms_response = requests.post(ms_url1, data=img_base)
# 转化为json格式,便于取数据
img_ms_response_json = json.loads(img_ms_response.content)
# 得到微软url
img_ms_url = img_ms_response_json["Host"] + img_ms_response_json["Url"]
# 请求测评
ms_url2 = r"https://kan.msxiaobing.com/Api/ImageAnalyze/Process?service=yanzhi&tid=1f2dc8a381324b5f94b5eb8a2b212587"
# 构造post请求头,其中cookie和referer不可缺,否则返回null
hea = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Firefox/60.0",
"Cookie": "cpid=YDAgSSFJxkheSixMfkkoMc-wlEznNFpIJzU-MyMzLUlIAA; salt=A3C081625F837C904F3BE4D202A74964; ai_user=WIdda|2018-05-22T02:25:08.861Z; ARRAffinity=b3bb36113778459332a680fea7d54df0c62e27d3ae6c8c7b478813f608a7df2e; ai_session=8l4ET|1527230783058|1527232952732",
"Referer": "https://kan.msxiaobing.com/ImageGame/Portal?task=yanzhi&feid=d9bbc18bf094ae43de8ce0bbc3943d42",
}
# 构造post数据
data = {
"Content[imageUrl]": img_ms_url,
"CreateTime": int(time.time()),
}
# 发起请求
response = requests.post(ms_url2, data=data, headers=hea)
# 转化为json数据
content_json = json.loads(response.content)
content = content_json["content"]["text"]
print(content)
img_url = r"http://mmbiz.qpic.cn/mmbiz_jpg/rViaJzEiap09VAhbw9c8WAzcfibic5icTnjerddrBvpoibDp0XficPw6QZcDIFffcmVFKjk7UOj6aFM1Rxks1XzHBAcMg/0"
face(img_url)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,781
|
Mr-big-c/github
|
refs/heads/master
|
/练习代码/Flask/flask_web/settings/secret.py
|
# -*- coding: utf-8 -*-
# @File : secret.py
# @Author: 一稚杨
# @Date : 2018/6/9/009
# @Desc : 机密数据配置文件,可以用来配置如数据库密码等参数
PASSWD = "123456"
SQLALCHEMY_DATABASE_URI = "mysql+cymysql://一稚杨:muyuyu123@localhost:3306/flask"
SQLALCHEMY_TRACK_MODIFICATIONS = True
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,782
|
Mr-big-c/github
|
refs/heads/master
|
/tkinter/绝对布局.py
|
"""
绝对布局
"""
import tkinter
win = tkinter.Tk()
win.title("hwy")
win.geometry("400x400")
# 创建三个标签
label1 = tkinter.Label(win, text="python", bg="blue")
label2 = tkinter.Label(win, text="java", bg="red")
label3 = tkinter.Label(win, text="C++", bg="pink")
# 指定位置,距离x,y,的距离
label1.place(x=0, y=0)
label2.place(x=50, y=50)
label3.place(x=100, y=100)
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,783
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-15/Attitude/templatetags/get_attitude_num.py
|
# -*- coding: utf-8 -*-
# @File : get_attitude_num.py
# @Author: 一稚杨
# @Date : 2018/8/15/015
# @Desc :
from Attitude.models import AttitudeCount, AttitudeRecord
from django import template
from django.contrib.contenttypes.models import ContentType
register = template.Library()
# 得到文章的表态的数据
@register.simple_tag
def get_attitude_num(content_type, object_id, attitude_type):
content_type = ContentType.objects.get(model=content_type)
attitude_num, create = AttitudeCount.objects.get_or_create(content_type=content_type, object_id=object_id)
return {
'flower': attitude_num.attitude_flower_num,
'handshake': attitude_num.attitude_handshake_num,
'pass': attitude_num.attitude_pass_num,
'shocking': attitude_num.attitude_shocking_num,
'egg': attitude_num.attitude_egg_num,
}.get(attitude_type, 'error')
# 判断当前用户对当前文章是否点赞
@register.simple_tag
def get_attitude_record(content_type, object_id, user, attitude_type):
# 判断是否登录,没有登录直接返回空
if not user.is_authenticated:
return ''
content_type = ContentType.objects.get(model=content_type)
if AttitudeRecord.objects.filter(content_type=content_type, object_id=object_id, attitude_user=user, attitude_type=attitude_type).exists():
# 存在点赞记录, 返回active
return 'active'
else:
return ''
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,784
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-11/Like/admin.py
|
from django.contrib import admin
from Like.models import LikeAr
# Register your models here.
class LikeArAdmin(admin.ModelAdmin):
list_display = ('user', 'Read_time', 'is_like', 'content_object')
admin.site.register(LikeAr, LikeArAdmin)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,785
|
Mr-big-c/github
|
refs/heads/master
|
/练习代码/微信公众号/robot.py
|
import requests
import json
# import time
# 创建post函数
def robot(content):
# 图灵api
api = r'http://openapi.tuling123.com/openapi/api/v2'
# userid = int(time.time())
# 创建post提交的数据
data = {
"perception": {
"inputText": {
"text": content
}
},
"userInfo": {
"apiKey": "672035b1bde5440e83eaexxxxxxx",
"userId": '672035b1bde5440',
}
}
# 转化为json格式
jsondata = json.dumps(data)
# 发起post请求
response = requests.post(api, data=jsondata)
# 将返回的json数据解码
robot_res = json.loads(response.content)
# 提取对话数据
print(robot_res["results"][0]['values']['text'])
# 创建对话死循环
while True:
# 输入对话内容
content = input("talk:")
robot(content)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,786
|
Mr-big-c/github
|
refs/heads/master
|
/代码中转站/client.py
|
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect_ex(("192.168.153.1", 8080))
while True:
data = input("发送的数据:")
client.send(data.encode("utf-8"))
response = client.recv(1024)
print(response.decode("utf-8"))
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,787
|
Mr-big-c/github
|
refs/heads/master
|
/代码中转站/blog/myapp/models.py
|
from django.db import models
from ckeditor_uploader.fields import RichTextUploadingField
# Create your models here.
class books(models.Model):
title = models.CharField(max_length=20)
content = RichTextUploadingField()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,788
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-15/Like/models.py
|
from django.db import models
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User
# Create your models here.
# 用于记录点赞数量的模型
class LikeCount(models.Model):
content_type = models.ForeignKey(ContentType, on_delete=models.DO_NOTHING)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')
# 用于记录点赞数量的字段
like_num = models.IntegerField(default=0)
# 用于记录点赞状态的模型
class LikeRecord(models.Model):
content_type=models.ForeignKey(ContentType, on_delete=models.DO_NOTHING)
object_id=models.PositiveIntegerField()
content_object=GenericForeignKey('content_type', 'object_id')
# 记录点赞的用户
like_user = models.ForeignKey(User, on_delete=models.DO_NOTHING)
# 记录点赞的时间
like_time = models.DateTimeField(auto_now_add=True)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,789
|
Mr-big-c/github
|
refs/heads/master
|
/实战项目/直线插补-数字积分法/直线插补-数字积分.py
|
"""
数字积分法--直线插补
"""
# -- coding:utf-8 --
import matplotlib.pyplot as plt
import tkinter
# 定义直线函数
def function(x, y):
xo = x[0]
xe = x[1]
yo = y[0]
ye = y[1]
# 得到斜率
k = (ye - yo)/(xe - xo)
# 得到b
b = ye - k*xe
return (k, b)
def is_ok(xo, yo, k, b):
num = k*xo + b - yo
# 设置精度
a = int(entry5.get())
num = round(num, a)
if k >= 0:
if float(entry2.get()) >= 0:
if num <= 0:
return 1
else:
return 0
else:
if num >= 0:
return 1
else:
return 0
else:
if float(entry2.get()) >= 0:
if num >= 0:
return 1
else:
return 0
else:
if num <= 0:
return 1
else:
return 0
# 插补函数
def runin(xo, yo, k, p, max_num, jrx, jry, xe, ye):
# 斜率大于等于零
if k >= 0:
# 终点在第一象限
if float(entry2.get()) >= 0:
# print(jrx, jry, max_num)
jrx = jrx + xe
jry = jry + ye
if jrx >= 2**max_num:
xo = xo + p
jrx = jrx - 2**max_num
if jry >= 2**max_num:
yo = yo + p
jry = jry - 2**max_num
# 终点在第三象限
else:
jrx = jrx + abs(xe)
jry = jry + abs(ye)
if jrx >= 2**max_num:
xo = xo - p
jrx = jrx - 2**max_num
if jry >= 2**max_num:
yo = yo - p
jry = jry - 2**max_num
result = (xo, yo, jrx, jry)
return result
# 斜率小于零
else:
# 终点在第四象限
if float(entry2.get()) >= 0:
jrx = jrx + abs(xe)
jry = jry + abs(ye)
if jrx >= 2**max_num:
xo = xo + p
jrx = jrx - 2**max_num
if jry >= 2**max_num:
yo = yo - p
jry = jry - 2**max_num
# 终点在第二象限
else:
jrx = jrx + abs(xe)
jry = jry + abs(ye)
if jrx >= 2**max_num:
xo = xo - p
jrx = jrx - 2**max_num
if jry >= 2**max_num:
yo = yo + p
jry = jry - 2**max_num
result = (xo, yo, jrx, jry)
return result
# 得到累加器的位数
def get_digit(max_num):
i = 1
while(1):
if 2**i >= max_num:
break
i = i + 1
return i
# 画出图形
def show():
plt.figure()
plt.title(u"line")
# print("起点:" + "\n")
xo = float(entry.get())
yo = float(entry1.get())
# print("终点" + "\n")
xe = float(entry2.get())
ye = float(entry3.get())
p = float(entry4.get())
x = (xo, xe)
y = (yo, ye)
max_num = max(abs(xe - xo), abs(ye - yo))
digit = get_digit(max_num)
result1 = function(x, y)
k = result1[0]
# b = result1[1]
plt.axis("equal")
plt.plot(x, y)
mode = R1.get()
txt.insert(tkinter.INSERT, "(" + str(xo) + "," + str(yo) + ")" + "\n")
if mode == 11:
jrx = 0
jry = 0
number = int((2**digit)/p)
elif mode == 22:
jrx = (2**digit)/2
jry = (2**digit)/2
number = int((2**digit)/p)
elif mode == 33:
jrx = 2**digit
jry = 2**digit
number = int((2**digit)/p - 1)
xe = xe - xo
ye = ye - yo
for i in range(number):
# print(xo, yo)
# print(result3)
result2 = runin(xo, yo, k, p, digit, jrx, jry, xe, ye) # 终点
plot_end = result2
plt.pause(0.5)
plt.plot((xo, plot_end[0]), (yo, plot_end[1]))
xo = plot_end[0]
yo = plot_end[1]
jrx = plot_end[2]
jry = plot_end[3]
txt.insert(tkinter.INSERT, "(" + str(xo) + "," + str(yo) + ")" + "\n")
plt.show()
# 清除数据
def clear():
txt.delete(0.0, tkinter.END)
win = tkinter.Tk()
win.title("hwy")
win.geometry("600x400")
win.resizable(width=False, height=False)
label1 = tkinter.Label(win, text="直线插补--数字积分法")
label1.pack()
label2 = tkinter.Label(win, text="起点坐标:Xo=")
label2.place(x=100, y=100)
e = tkinter.Variable()
entry = tkinter.Entry(win, textvariable=e)
e.set(0)
entry.place(x=200, y=100)
label3 = tkinter.Label(win, text="起点坐标:Yo=")
label3.place(x=100, y=130)
e1 = tkinter.Variable()
entry1 = tkinter.Entry(win, textvariable=e1)
e1.set(0)
entry1.place(x=200, y=130)
label4 = tkinter.Label(win, text="终点坐标:Xe=")
label4.place(x=100, y=160)
e2 = tkinter.Variable()
entry2 = tkinter.Entry(win, textvariable=e2)
e2.set(10)
entry2.place(x=200, y=160)
label5 = tkinter.Label(win, text="终点坐标:Ye=")
label5.place(x=100, y=190)
e3 = tkinter.Variable()
entry3 = tkinter.Entry(win, textvariable=e3)
e3.set(10)
entry3.place(x=200, y=190)
label6 = tkinter.Label(win, text="脉冲当量:P=")
label6.place(x=100, y=220)
e4 = tkinter.Variable()
entry4 = tkinter.Entry(win, textvariable=e4)
e4.set(1)
entry4.place(x=200, y=220)
label7 = tkinter.Label(win, text="精度:A=")
label7.place(x=100, y=250)
e5 = tkinter.Variable()
entry5 = tkinter.Entry(win, textvariable=e5)
e5.set(5)
entry5.place(x=200, y=250)
# 显示坐标值
txt = tkinter.Text(win)
txt.place(x=400, y=30)
button = tkinter.Button(win, text="插补计算", command=show)
button.place(x=250, y=350)
button1 = tkinter.Button(win, text="清除坐标", command=clear)
button1.place(x=340, y=350)
R1 = tkinter.IntVar()
radio3 = tkinter.Radiobutton(win, text="不加载", value=11, variable=R1)
radio3.place(x=100, y=280)
radio4 = tkinter.Radiobutton(win, text="半加载", value=22, variable=R1)
radio4.place(x=200, y=280)
radio4 = tkinter.Radiobutton(win, text="全加载", value=33, variable=R1)
radio4.place(x=300, y=280)
R1.set(11)
win.mainloop()
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,790
|
Mr-big-c/github
|
refs/heads/master
|
/练习代码/spider5.15/将爬取的数据直接存入文件.py
|
import urllib.request
response = urllib.request.urlretrieve(r"http://www.baidu.com/", filename=r"C:\Users\Administrator\Desktop\hwy.html")
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,791
|
Mr-big-c/github
|
refs/heads/master
|
/练习代码/Flask/6.3/2.py
|
# -*- coding: utf-8 -*-
# @File : 2.py
# @Author: 一稚杨
# @Date : 2018/6/3/003
# @Desc : 模板文件的使用
# 对于flask而言,模板文件的加载有两种情况,一种是使用模块,另一种是使用包
# 当你使用模板文件时,flask会自动到你的项目目录下的一个名为templates的文件中
# 去寻找指定的模板文件,所以所有的模板文件都应该放在templates这个文件夹中
from flask import Flask, render_template
# 创建一个flask应用
app = Flask(__name__)
# 创建路由并指定视图函数,通过加载静态模板来显示页面
@app.route("/index")
def index():
# render_template 的第一个参数是模板文件,第二个参数是需要渲染的数据
data = {"name": "一稚杨", "age": 20}
return render_template("index.html", data=data)
# 运行app
if __name__ == "__main__":
app.run(debug=True)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,792
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-17/Attitude/admin.py
|
from django.contrib import admin
from .models import AttitudeCount, AttitudeRecord
# Register your models here.
class AttitudeCountAdmin(admin.ModelAdmin):
list_display = ('pk', 'content_object', 'attitude_flower_num', 'attitude_handshake_num', 'attitude_pass_num', 'attitude_shocking_num', 'attitude_egg_num')
class AttitudeRecordAdmin(admin.ModelAdmin):
list_display = ('pk', 'content_object', 'attitude_type', 'attitude_user', 'attitude_time')
admin.site.register(AttitudeCount, AttitudeCountAdmin)
admin.site.register(AttitudeRecord, AttitudeRecordAdmin)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,793
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-17/Like/templatetags/get_like_num.py
|
# -*- coding: utf-8 -*-
# @File : get_like_num.py
# @Author: 一稚杨
# @Date : 2018/8/14/014
# @Desc : 通过传递过来的类型、相关参数得到对应的点赞数量并返回
from Like.models import LikeCount, LikeRecord
from django import template
from django.contrib.contenttypes.models import ContentType
register = template.Library()
# 得到点赞数量
@register.simple_tag
def get_like_num(content_type, object_id):
content_type = ContentType.objects.get(model=content_type)
like_num, create = LikeCount.objects.get_or_create(content_type=content_type, object_id=object_id)
like_num = like_num.like_num
return like_num
# 判断当前用户对当前文章是否点赞
@register.simple_tag
def get_like_record(content_type, object_id, user):
# 判断是否登录,没有登录直接返回空
if not user.is_authenticated:
return ''
content_type = ContentType.objects.get(model=content_type)
if LikeRecord.objects.filter(content_type=content_type, object_id=object_id, like_user=user).exists():
# 存在点赞记录, 返回active
return 'active'
else:
return ''
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,794
|
Mr-big-c/github
|
refs/heads/master
|
/练习代码/Flask/6.3/3.py
|
# -*- coding: utf-8 -*-
# @File : 3.py.py
# @Author: 一稚杨
# @Date : 2018/6/4/004
# @Desc : 静态文件的使用
from flask import Flask, render_template
# 创建一个flask应用
app = Flask(__name__)
# 指定路由并设置对应的视图函数
@app.route("/index")
def index():
return render_template("index.html")
# 启动应用
if __name__ == "__main__":
app.run(debug=True)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,795
|
Mr-big-c/github
|
refs/heads/master
|
/Flask/Flask_win/flask_web/settings/setting.py
|
# -*- coding: utf-8 -*-
# @File : setting.py
# @Author: 一稚杨
# @Date : 2018/6/9/009
# @Desc : 普通配置文件
DEBUG = True
# SQLALCHEMY_DATABASE_URI = "mysql+pymysql://一稚杨:muyuyu123@localhost:3306/flask"
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,796
|
Mr-big-c/github
|
refs/heads/master
|
/快捷办公/编码和解码.py
|
path = r"C:\Users\Administrator\Desktop\1234.txt"
with open(path, "wb") as f:
str = "hwy is a good man黄"
f.write(str.encode("utf-8"))
with open(path, "rb", errors="ignore") as f1:
data = f1.read()
# 得到的是一个二进制文件
print(data)
print(type(data))
# 解码,需要注意的是:解码和编码格式需要一致
newdata = data.decode("gbk")
print(newdata)
print(type(newdata))
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,797
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-15/myapp/views.py
|
from django.shortcuts import render, HttpResponse, HttpResponseRedirect
from django.core.paginator import Paginator
from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from django.contrib import auth
from .models import *
from .forms import *
from Recent_Read.models import Recent_Read
from django.contrib.contenttypes.models import ContentType
# Create your views here.
# 显示文章数据
def show_Articles_data(request):
data = Article.objects.all()
# 得到get请求中的页码参数
page_num = request.GET.get('page', 1)
# 实例化一个分页器
paginator = Paginator(data, 8)
# 通过页码获得对应的文章,可以使用paginator.page, 但是这个方法不能对get获得的数据进行筛选,所以使用get_page
article_list = paginator.get_page(page_num)
# 前端页面参数字典
context = {}
context['data'] = article_list.object_list
context['obj'] = article_list
context['user'] = request.user
# 判断是否当前页是否是第一页
if int(article_list.number) == 1:
# 总页数超过3页
if (int(article_list.number) + 2) <= paginator.num_pages:
context["page_num"] = range(int(article_list.number), int(article_list.number) + 3)
else:
context["page_num"]=range(int(article_list.number), int(paginator.num_pages) + 1)
# 判断是否是最后一页
elif not article_list.has_next():
if (int(article_list.number) - 2) > 0:
context["page_num"]=range(int(article_list.number) - 2, int(article_list.number) + 1)
else:
context["page_num"]=range(1, int(article_list.number) + 1)
else:
if (int(article_list.number) - 1) > 0 and (int(article_list.number) + 1) <= paginator.num_pages:
context['page_num'] = range(int(article_list.number) - 1, int(article_list.number) + 2)
elif (int(article_list.number) - 1) <= 0 and (int(article_list.number) + 1) <= paginator.num_pages:
context['page_num']=range(1, int(article_list.number) + 2)
else:
context['page_num']=range(1, int(article_list.number) + 1)
return render(request, 'index.html', context)
def content(request):
pk = request.GET.get('pk')
try:
# 通过获得get请求中的数据查询文本内容,根据判断长度来确定是否查找到数据(数据是否存在)
# 存在数据,则在原数据的基础上加1
articles = Article.objects.get(pk=pk)
ct = ContentType.objects.get_for_model(Article)
# 判断用户是否登录,如果已经登录,则实例化一个历史记录并保存生效
if not request.user.is_anonymous:
re = Recent_Read(content_type=ct, object_id=pk,user=request.user)
re.save()
if Read_Num.objects.filter(article=articles).count():
articles.read_num.read_num_data += 1
articles.read_num.save()
# 不存在数据,创建对象,并且使阅读数设置为0
else:
readnum = Read_Num()
readnum.article = articles
readnum.read_num_data = 1
readnum.save()
text = articles.text
context = {}
context['text'] = text
context['pk'] = pk
context['user'] = request.user
return render(request, 'content_template.html', context)
except:
return HttpResponse('404')
# 用户登录
def login(request):
if request.method == "GET":
context = {}
context['previous_page'] = request.GET.get('from_page', '/index')
return render(request, 'login.html', context)
else:
username = request.POST['username']
password = request.POST['password']
try:
user = authenticate(request, username=username, password=password)
auth.login(request, user)
return HttpResponseRedirect(request.GET.get('from_page', '/index'))
except:
context = {}
context['login_info'] = True
context['previous_page']=request.GET.get('from_page', '/index')
return render(request, 'login.html', context)
# 用户注销
def logout(request):
auth.logout(request)
return HttpResponseRedirect(request.GET.get('from_page', '/index'))
# 用户注册
def register(request):
if request.method == "GET":
context = {}
context['previous_page'] = request.GET.get('from_page', '/index')
return render(request, 'register.html', context)
else:
try:
username = request.POST['username']
password = request.POST['password']
# 判断用户名是否存在
if User.objects.filter(username=username).exists():
context = {}
context['register_info'] = True
context['previous_page']=request.GET.get('from_page', '/index')
return render(request, 'register.html', context)
else:
user = User.objects.create_user(username=username, password=password)
user.save()
return HttpResponseRedirect(request.GET.get('from_page', '/index'))
except:
return HttpResponse('注册过程异常,请重新注册!')
# Django form表单测试
def loginform(request):
if request.method == 'POST':
login_form = LoginForm(request.POST)
# 判断接受的数据是否有效,有效则为True,否则为FALSE(比如输入的是一串空格)
if login_form.is_valid():
user = login_form.cleaned_data['user']
auth.login(request, user)
return HttpResponseRedirect(request.GET.get('from_page'))
else:
# 实例化一个Form表单对象
login_form = LoginForm()
context = {}
# 传递给模板文件
context['login_form'] = login_form
return render(request, 'test.html', context)
# 测试用视图函数
def test(request):
user = request.user
print(dir(user))
print(user.is_anonymous)
return HttpResponse('test')
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,798
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-11/Run/migrations/0002_auto_20180812_1039.py
|
# Generated by Django 2.0 on 2018-08-12 02:39
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('Run', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='run',
options={'ordering': ['-time']},
),
]
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,799
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog8-10/Recent_Read/models.py
|
from django.db import models
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User
# Create your models here.
class Recent_Read(models.Model):
content_type = models.ForeignKey(ContentType, on_delete=models.DO_NOTHING)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')
Read_time = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey(User, on_delete=models.DO_NOTHING)
is_delete = models.BooleanField(default=False)
class Meta:
ordering = ['-Read_time']
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,800
|
Mr-big-c/github
|
refs/heads/master
|
/练习代码/Flask/flask_web/run_app.py
|
# -*- coding: utf-8 -*-
# @File : run_app.py
# @Author: 一稚杨
# @Date : 2018/6/8/008
# @Desc : 引入create_app方法创建一个app并运行
import sys
sys.path.append(r'C:\Users\Administrator\Desktop\Flask')
from flask_web import create_app
app = create_app()
if __name__ == "__main__":
app.run(debug=app.config["DEBUG"])
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
19,801
|
Mr-big-c/github
|
refs/heads/master
|
/Blog Relevant/blog_counter/myapp/admin.py
|
from django.contrib import admin
from .models import *
# Register your models here.
# 注册模型Article
class ArticleAdmin(admin.ModelAdmin):
list_display = ('id', 'title', 'author', 'text', 'readnum')
# 注册模型Read_Num
class Read_NumAdmin(admin.ModelAdmin):
list_display = ('id', 'read_num_data', 'article')
admin.site.register(Article, ArticleAdmin)
admin.site.register(Read_Num, Read_NumAdmin)
|
{"/Blog Relevant/files_system/basics/views.py": ["/Blog Relevant/files_system/basics/file_op.py"], "/Blog Relevant/blog7-17/myapp/admin.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/Blog Relevant/blog8-31/myapp/views.py": ["/Blog Relevant/blog8-31/myapp/forms.py"], "/Blog Relevant/blog7-21/myapp/views.py": ["/Blog Relevant/blog7-21/myapp/models.py"], "/Blog Relevant/blog7-17/myapp/views.py": ["/Blog Relevant/blog7-17/myapp/models.py"], "/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/views1.py": ["/\u7ec3\u4e60\u4ee3\u7801/Flask/flask_web/blueprint1/views/__init__.py"]}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.