随笔分类 -  Python / 全栈

摘要:1、动态Form form_handle.py from django.forms import ModelForm def create_dynamic_model_form(admin_class,form_add=False): """动态的生成modelform form_add: Fals 阅读全文
posted @ 2024-02-13 00:03 Bruce_JRZ 阅读(35) 评论(0) 推荐(0)
摘要:Django提供了Admin来做后台管理 这里Kingadmin为自己做的后台管理 1、Kingadmin Base from django.shortcuts import render class BaseKingAdmin(object): list_display = [] list_fil 阅读全文
posted @ 2024-02-12 23:57 Bruce_JRZ 阅读(24) 评论(0) 推荐(0)
摘要:role base access control 基于角色的权限控制 1、Models from django.db import models class User(models.Model): name = models.CharField(max_length=32) password = m 阅读全文
posted @ 2024-02-12 23:41 Bruce_JRZ 阅读(63) 评论(0) 推荐(0)
摘要:XSSFilter.py from bs4 import BeautifulSoup class XSSFilter(object): __instance = None def __init__(self): # XSS白名单 self.valid_tags = { "font": ['color 阅读全文
posted @ 2024-02-12 23:09 Bruce_JRZ 阅读(18) 评论(0) 推荐(0)
摘要:check_code.py(需要字体文件:Monaco.ttf) import random from PIL import Image, ImageDraw, ImageFont, ImageFilter _letter_cases = "abcdefghjkmnpqrstuvwxy" # 小写字 阅读全文
posted @ 2024-02-12 18:16 Bruce_JRZ 阅读(38) 评论(0) 推荐(0)
摘要:def login(request): if request.method == 'GET': form = account.LoginForm() return render(request, 'login.html',{'form':form }) else: form = account.Lo 阅读全文
posted @ 2024-02-12 17:38 Bruce_JRZ 阅读(11) 评论(0) 推荐(0)
摘要:web项目中,向其它ip地址发送请求时会受到浏览器同源策略的限制 : 对方受到请求,并作出响应,但浏览器限制了接受响应。 # 受到同源策略的限制 $.ajax({ url:'http://127.0.0.1:9000/ajax_jsonp.html', type:'GET', data:{}, su 阅读全文
posted @ 2024-02-12 00:05 Bruce_JRZ 阅读(18) 评论(0) 推荐(0)
摘要:1、普通上传 <body> <form action="/upload.html" method="post" enctype="multipart/form-data"> {% csrf_token %} <input type="text" name="user"/> <input type=" 阅读全文
posted @ 2024-02-11 23:48 Bruce_JRZ 阅读(14) 评论(0) 推荐(0)
摘要:Serializers Django中,自定义类型的对象无法通过json序列化,可以使用serializers。 def get_data(request): # 由于UserInfo是自定义对象,不能通过json序列化 # 因此使用以下方式 from django.core import seri 阅读全文
posted @ 2024-02-11 23:44 Bruce_JRZ 阅读(26) 评论(0) 推荐(0)
摘要:Django的Form: 1、对用户请求的验证 2、生成HTML代码 a、创建一个类 b、类中创建字段(包含正则表达式) c、Get a) Obj = Fr() obj.user=> 自动生成HTML d、POST a) Obj = Fr(request,POST) i. If obj.is_val 阅读全文
posted @ 2024-02-11 23:42 Bruce_JRZ 阅读(34) 评论(0) 推荐(0)
摘要:原理 def index(request): per_page_count = 10 current_page=request.GET.get('p') # page=1 0,10 0-9 # page=2 10,20 10-19 current_page = int(current_page) s 阅读全文
posted @ 2024-02-11 23:33 Bruce_JRZ 阅读(22) 评论(0) 推荐(0)