django

Django REST framework API认证(包括JWT认证)

ぃ、小莉子 提交于 2021-02-17 12:50:40
Django REST framework API认证(包含JWT认证) + 权限 发表于 2019-02-24 | 分类于 Django , PYTHON | 0 | 阅读次数: 30 字数统计: 6.3k | 阅读时长 ≈ 26 Django REST framework API认证(包含JWT认证) + 权限 Django REST framework API认证(包含JWT认证) 一. 背景 在我们学习Django Rest Framework(简称DRF)时,其非常友好地给我们提供了一个可浏览API的界面。很多测试工作都可以在可浏览API界面完成测试。要使用可浏览API界面很简单,只需要在urls.py文件中添加如下部分即可。 1 2 3 4 from django.conf.urls import include urlpatterns += [ url( r'^api-auth/' , include( 'rest_framework.urls' , namespace= 'rest_framework' )) ] 其中, r'^api-auth/' 部分实际上可以用任何你想使用URL替代,唯一的限制是所包含的URL必须使用 'rest_framework' 命名空间。在Django 1.9+中,REST framework将自动设置,所以你也无须关心。 配置完成后

Python面试题之Python面试题汇总

三世轮回 提交于 2021-02-17 12:24:25
参考地址 目录 Python基础篇 1:为什么学习Python 2:通过什么途径学习Python 3:谈谈对Python和其他语言的区别 Python的优势: 4:简述解释型和编译型编程语言 5:Python的解释器种类以及相关特点? 6:位和字节的关系 7:b、B、KB、MB、GB的关系 8:PE8规范 9:通过代码实现如下转换(进制之间转换) 10:请编写一个函数实现将IP地址转换成一个整数 11、python递归的最大层数?998 12:求结果(and or or) 运算符 13 :ascii、unicode、utf-8、gbk 区别 14:字节码和机器码的区别 15:三元运算写法和应用场景? 16:Python3和Python2的区别? 17:用一行代码实现数值交换 18:Python3和Python2中int和long区别 19:xrange和range的区别 20:文件操作时:xreadlines和readlines的区别? 21: 列列举布尔值为False的常见值? 22. 字符串、列表、元组、字典每个常用的5个方法? 23、 lambda表达式格式以及应用场景? 24. pass的作用 25. *arg和**kwarg作用 26. is和==的区别 27:谈谈Python的深浅拷贝?以及实现方法和应用场景。 28. Python垃圾回收机制? 29.

django days-of-week representation in model

流过昼夜 提交于 2021-02-17 09:55:57
问题 I have this "Jobs Server" model that i'm building. I want to include a field that will save which days of the week this job will run on. Ultimately in the UI, i would like the user to be able to have a series of check boxes(one for each day) that they can select. What would be the best way to represent this "days-of-week" data in my mode? class Job(models.Model): name = models.CharField(max_length=32, unique=True) package = models.ForeignKey(Package) binary = models.ForeignKey(Binary) host =

How to serialize a queryset from an unrelated model as a nested serializer?

旧城冷巷雨未停 提交于 2021-02-17 09:41:30
问题 I'm trying to add a nested serializer to an existing serializer based on some criteria of the parent model, not a Foreign key. The use case is to return a 'Research' object with an array of 'ResearchTemplate' objects that are identified by filtering on a Postgres ArrayField. Models class Research(TimeStampedModel): category = models.CharField(max_length=100, choices=RESEARCH_TEMPLATE_CATEGORIES, default='quote') body = models.CharField(max_length=1000, blank=True, default='') #The body of

Python中的mixin模式

Deadly 提交于 2021-02-17 09:39:45
转载注明,本文链接: http://www.bianbingdang.com/article_detail/167.html MixIn和继承的关系 面向对象三大特征,继承、封装、多态。第一次看到MixIn的时候,弄不懂这个和继承有什么关系/区别。首先,继承是父亲和儿子的关系,而python minxin是混入的意思。虽然,MinIn子类可以使用,父类的方法,但这并不是一种继承的关系,而是父类为子类提供了一种可用的方法。 继承的诟病 子类、父类继承关系过多,会导致思维上的混乱,比如我们的父类派生出很多个子类,我们会一直考虑继承了XXX,如果父类没有这个方法,则子类再创造一个方法,那么子类这个方法多个地方用到,我们又得把它加入到父类才行,这样下来并不是很合适。 MixIn MixIn的方式则没有那么得拘束,例如有个Persion类 class Person(): pass 这个人需要修电脑,但是我不会修怎么办。那我写个修电脑的方法给他,那显然不合适。那怎么办,刚好这个人有个朋友,过来帮帮忙吧。 class FriendMixIn(): def repair_compute: return True class Person(FriendMixIn): pass 那么很快就明白,MixIn相当于在原来的基础上,锦上添花。他是包含的意思,而不是继承的关系。

What does “'tests' module incorrectly imported” mean?

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-17 09:11:32
问题 I have copied a working test line by line and just changed a few names (at least so I thought) and now I get this very cryptic error: (I have replaced some stuff with FOO, BAR) ImportError: 'tests' module incorrectly imported from 'FOO/exports/tests'. Expected 'FOO/exports'. Is this module globally installed? The problem is that I do not understand the error at all. What does this error message mean? Complete stacktrace: Traceback (most recent call last): File "BAR/modeling/manage.py", line

What does “'tests' module incorrectly imported” mean?

耗尽温柔 提交于 2021-02-17 09:10:50
问题 I have copied a working test line by line and just changed a few names (at least so I thought) and now I get this very cryptic error: (I have replaced some stuff with FOO, BAR) ImportError: 'tests' module incorrectly imported from 'FOO/exports/tests'. Expected 'FOO/exports'. Is this module globally installed? The problem is that I do not understand the error at all. What does this error message mean? Complete stacktrace: Traceback (most recent call last): File "BAR/modeling/manage.py", line

What does “'tests' module incorrectly imported” mean?

泄露秘密 提交于 2021-02-17 09:08:28
问题 I have copied a working test line by line and just changed a few names (at least so I thought) and now I get this very cryptic error: (I have replaced some stuff with FOO, BAR) ImportError: 'tests' module incorrectly imported from 'FOO/exports/tests'. Expected 'FOO/exports'. Is this module globally installed? The problem is that I do not understand the error at all. What does this error message mean? Complete stacktrace: Traceback (most recent call last): File "BAR/modeling/manage.py", line

部署前后端分离项目

风格不统一 提交于 2021-02-17 09:04:01
路飞前后端项目部署 前言 使用软件 vue 部署前段 uwsgi uWSGI是一个全功能的HTTP服务器,实现了WSGI协议、uwsgi协议、http协议等。它要做的就是把HTTP协议转化成语言支持的网络协议。比如把HTTP协议转化成WSGI协议,让Python可以直接使用。 centos7 系统环境 virtulenv 在虚拟环境中部署后端项目 nginx 使用nginx做反向代理 redis 存储数据 mysql(mariadb) 存储数据 supervisor Linux/Unix系统下的一个进程管理工具,不支持Windows系统。它可以很方便的监听、启动、停止、重启一个或多个进程。用Supervisor管理的进程,当一个进程意外被杀死,supervisort监听到进程死后,会自动将它重新拉起,很方便的做到进程自动恢复的功能,不再需要自己写shell脚本来控制。 项目部署 准备工作 1 将项目上传到服务器上 方法一:使用xftp工具,进项上传文件夹,将项目代码,传到linux服务器当中 这个页面操作,实在不会百度 方式2: 使用scp从本地将文件上传到linux服务器中 scp -r 本地文件夹 远程用户名@远程ip:远程文件夹/ 2 将mysql数据迁移到服务器数据库 服务器端安装mysql(mariadb)数据库链接: https://www.cnblogs.com

Django edit user profile

拥有回忆 提交于 2021-02-17 09:02:01
问题 I'm trying to create an "Edit Profile" form in the fronted. What happens is that my form(i'm not 100% sure) tries to create a user instead of finding the current user and update his profile. So I think that's the issue. Checked many questions here but none was clear enough. The fields I'm trying to edit are email, first name and last name. (Also I would like to add uda forms.py class UpdateProfile(forms.ModelForm): username = forms.CharField(required=True) email = forms.EmailField(required