随笔分类 -  django

摘要:url(r'^invite_code/(?P<invite_code>[a-zA-Z0-9]+)/$', candidate_views.AiReportViewSet.as_view({'get': 'retrieve'})), 匹配字母,数字写法 阅读全文
posted @ 2020-09-14 17:20 夜晚的潜水艇 阅读(142) 评论(0) 推荐(0)
摘要:前提: 基于Django drf框架 urls.py url传参'xxxxx/xxxx/(?P<code>\w+)/(?P<id>\d+)$' views.py 类视图 取参 look_url_kwargs = ("code", 'id') code = self.kwargs.get('code' 阅读全文
posted @ 2020-09-05 14:14 夜晚的潜水艇 阅读(318) 评论(0) 推荐(0)
摘要:first %s 单个占位符使用 'xxxxxxx %s xxx' %s second 多个占位符使用 'xxxxx %s xxxxxx %s xxxxxxx' % (params1, params2) 阅读全文
posted @ 2020-09-05 14:09 夜晚的潜水艇 阅读(472) 评论(0) 推荐(0)
摘要:判断用户是否是第一次登陆系统 middleware.py from users.models import User class LoginINMiddleware: def __init__(self, get_response): self.get_response = get_response 阅读全文
posted @ 2020-07-28 16:46 夜晚的潜水艇 阅读(84) 评论(0) 推荐(0)
摘要:跨域产生的原因: 核心问题是:浏览器的同源策略,协议(http/https),域名,端口号一致, 凡是违背这个规定的两个网站都会被当作跨域处理 第1种方法: settings中配置跨域,不详细讲,网上很多 第二种方法: API 返回的响应头里面加上跨域headers, 这样可以解决跨域,上线后 将‘ 阅读全文
posted @ 2020-07-07 11:10 夜晚的潜水艇 阅读(151) 评论(0) 推荐(0)
摘要:from flask import Flask, request app = Flask(__name__) @app.route('/upload', methods=['POST'])def upload(): file_obj = request.files.get('pic') if fil 阅读全文
posted @ 2020-05-09 13:30 夜晚的潜水艇 阅读(929) 评论(0) 推荐(0)
摘要:<form method='post' enctype='multipart/form-data'> # multipart/from-data 指定多媒体类型 <input type='text' name='city'><input type='text' name='age'><input t 阅读全文
posted @ 2020-05-09 11:14 夜晚的潜水艇 阅读(1507) 评论(0) 推荐(0)
摘要:查询一个月内每天的查询人数 from django.db.models import Count data = ApplicationForm.objects.filter(create_time__year=year, create_time__month=month).extra( select 阅读全文
posted @ 2020-03-29 23:01 夜晚的潜水艇 阅读(1576) 评论(0) 推荐(0)
该文被密码保护。
posted @ 2020-03-03 11:22 夜晚的潜水艇 阅读(0) 评论(0) 推荐(0)
摘要:models.py class Counties(BaseModel): countname = models.CharField(max_length=128, verbose_name="国家名称", null=True, blank=True) phoneareacode = models.I 阅读全文
posted @ 2020-02-26 22:37 夜晚的潜水艇 阅读(1281) 评论(0) 推荐(0)
摘要:过滤 对于列表数据可能需要根据字段进行过滤,我们可以通过添加 django-filter 扩展来增强支持。 pip install django-filter 在配置文件中增加过滤后端的设置: INSTALLED_APPS = [ ... 'django_filters', # 需要注册应用, ] 阅读全文
posted @ 2020-02-25 17:14 夜晚的潜水艇 阅读(177) 评论(0) 推荐(0)
摘要:from rest_framework import permissions from django.contrib.auth.models import AnonymousUser from models import User class IsCandidate(permissions.Base 阅读全文
posted @ 2020-02-25 14:27 夜晚的潜水艇 阅读(140) 评论(0) 推荐(0)
该文被密码保护。
posted @ 2020-02-25 11:58 夜晚的潜水艇 阅读(0) 评论(0) 推荐(0)
摘要:class PositionListView(generics.ListAPIView): serializer_class = PositionListSerializer filter_backends = (DjangoFilterBackend,) filter_fields = ('typ 阅读全文
posted @ 2020-02-18 17:59 夜晚的潜水艇 阅读(333) 评论(0) 推荐(0)
摘要:models.py class CompanyTenant(models.Model): tenant_id = 'id' created_date = models.DateTimeField( auto_now_add=True, ) name = models.CharField( max_l 阅读全文
posted @ 2020-02-12 14:46 夜晚的潜水艇 阅读(450) 评论(0) 推荐(0)
摘要:from itsdangerous import TimedJSONWebSignatureSerializer as Serializer 1 实例化对象 serializer = Serializer('secretkey', 3600) # 3600 代表过期时间 单位秒2 加密信息info 阅读全文
posted @ 2020-02-04 00:04 夜晚的潜水艇 阅读(720) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2020-02-02 17:55 夜晚的潜水艇 阅读(202) 评论(0) 推荐(0)
摘要:phone = '15189827893' list = phone[3:7] new_phone = phone.replace(list, '****') print(new_phone) 阅读全文
posted @ 2020-01-22 21:28 夜晚的潜水艇 阅读(3584) 评论(0) 推荐(0)
摘要:models.py class Candidate(BaseModel): name = models.CharField(max_length=64, verbose_name="候选人姓名", null=True, blank=True) email = models.EmailField(nu 阅读全文
posted @ 2020-01-22 19:01 夜晚的潜水艇 阅读(745) 评论(0) 推荐(0)
摘要:settings.py STATIC_URL = '/api/static/' MEDIA_URL = '/api/media/' # MEDIA_ROOT = 'media' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') STATICFILES_DIRS 阅读全文
posted @ 2020-01-19 15:45 夜晚的潜水艇 阅读(411) 评论(0) 推荐(0)