![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
django源码
top啦它
这个作者很懒,什么都没留下…
展开
-
ajax使用post传输还是会在地址栏出现输入数据
https://www.cnblogs.com/hyc-go/p/11128920.htmlajax使用post传输还是会在地址栏出现输入数据今天写代码,发现ajax使用post传输还是会在地址栏出现输入数据,后来把input的name属性去掉就好。记录一下。转载 2021-05-23 19:14:03 · 298 阅读 · 0 评论 -
修改QueryDict的几种方式
简介 在正常的请求/响应周期中访问时,request.POST和request.GET上的QueryDict将是不可变的. 要获得可变版本,您需要使用QueryDict.copy()或者._mutable = True1、第一种方式: 用request.POST调用_mutable并修改为True reuqets.POST._mutable = True2、第二种方式: <QueryDict: {'title': ['水浒传2'],转载 2021-05-23 14:13:56 · 632 阅读 · 0 评论 -
django将request传入Form
forms.pyclass Personal_data_Form(forms.ModelForm): nickname = forms.CharField(max_length=20,help_text='长度控制在20个字内',label='昵称') self_introduction = forms.CharField(max_length=200,empty_value = 'aa',strip='sss',label='个人介绍')#加入request=None def原创 2021-05-15 15:27:39 · 492 阅读 · 0 评论 -
django发送邮件配置
settings.pyEMAIL_HOST = 'smtp.qq.com'# Port for sending email.EMAIL_PORT = 587# Optional SMTP authentication information for EMAIL_HOST.EMAIL_HOST_USER = '3********3@qq.com'EMAIL_HOST_PASSWORD = 'u**************c'EMAIL_USE_TLS = True # 必须为TrueEMAI原创 2021-05-15 11:36:24 · 261 阅读 · 0 评论 -
django上传图片,并在后端处理
@login_requireddef head_portrait(request): if request.method == 'GET': user = request.user context = { 'user':user } return render(request,'Modify_personal_data/head_portrait.html',context) elif request.原创 2021-05-15 11:33:55 · 257 阅读 · 0 评论 -
django在url中配置静态资源
在主urls.py中添加:urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)原创 2021-05-14 11:46:40 · 342 阅读 · 0 评论 -
django中的to_internal_value和to_representation
要更新序列化程序的外部字段,我们使用serializer.relatedField,它有两个函数to_representation和to_internal_value 。 to_representation用于修改API的GET主体, to_internal_value用于验证序列化程序的更新请求,例如,它将帮助您检查更新relatedField的请求是否存在于其他表中或不存在。假设我们有两个模型,一个是Foo ,另一个是Bar和Foo是Bar外键,因此我们需要编写以下序列化程序来验证和更新外键。这是代转载 2021-05-12 23:54:12 · 988 阅读 · 0 评论 -
etag&last_modified&condition& django.middleware.http.ConditionalGetMiddleware
views.pyfrom django.http import HttpResponse, HttpResponseRedirect, Http404, HttpResponseNotFoundfrom django.shortcuts import render# Create your views here.from django.views.decorators.http import etag, last_modified, conditionfrom syboy1.models im原创 2021-05-11 18:26:21 · 180 阅读 · 0 评论 -
django.utils.encoding未发现 python_2_unicode_compatible包
python3+Django3请使用from six import python_2_unicode_compatible替代from django.utils.encoding import python_2_unicode_compatible转载 2021-05-10 23:44:15 · 384 阅读 · 0 评论 -
django配置缓存
setting.py中添加CACHES = { "default":{ "BACKEND":"django_redis.cache.RedisCache", "LOCATION":"redis://127.0.0.1:6379/1", "TIMEOUT":300, "OPTIONS":{ "CLIENT_CLASS":"django_redis.client.DefaultClient",原创 2021-05-09 18:53:50 · 98 阅读 · 0 评论 -
Django模型之Meta选项详解
原链接Django模型之Meta选项详解Django模型类的Meta是一个内部类,它用于定义一些Django模型类的行为特性。而可用的选项大致包含以下几类abstract这个属性是定义当前的模型是不是一个抽象类。所谓抽象类是不会对应数据库表的。一般我们用它来归纳一些公共属性字段,然后继承它的子类可以继承这些字段。Options.abstract如果abstract = True 这个model就是一个抽象类app_label这个选型只在一种情况下使用,就是你的模型不在默认的应用程序包下的mo转载 2021-01-13 16:35:32 · 339 阅读 · 0 评论 -
django 源码dispatch和getattr分析
def dispatch(self, request, *args, **kwargs): # Try to dispatch to the right method; if a method doesn't exist, # defer to the error handler. Also defer to the error handler if the # request method isn't on the approved list. ...原创 2020-11-26 00:07:31 · 477 阅读 · 0 评论 -
Django AttributeError: ‘Blog‘ object has no attribute ‘object_list‘
写django时,将form渲染到Html中时,出现该错误Traceback (most recent call last): File "C:\Users\top\anaconda3\lib\site-packages\django\core\handlers\exception.py", line 34, in inner response = get_response(request) File "C:\Users\top\anaconda3\lib\site-packages\dj原创 2020-11-21 13:27:33 · 613 阅读 · 0 评论 -
get_object_or_404
article = get_object_or_404(BlogArticles, id=article_id)get_object_or_404(Modename, pk=__)获取Modename中的pk,如果获取到返回pk对应的一系列数据,否则返回404原创 2020-11-19 21:22:32 · 446 阅读 · 0 评论 -
APPEND_SLASH
当APPEND_SLASH为True时,http://127.0.0.1:8000/up/users/1可以访问,为False时,必须在1后面加一个 /原创 2020-11-19 15:38:01 · 583 阅读 · 0 评论 -
users.UserProfile: (auth.E003) ‘UserProfile.username‘ must be unique because it is named as the ‘USE
在重写django的User model时,需要将username设置为unique=True,否则会报这个错误。原创 2020-11-19 14:45:52 · 3052 阅读 · 0 评论 -
TypeError: “ModelBase is not iterable”
再写django项目时,出现错误TypeError: “ModelBase is not iterable”原因是将models.py中定义的类作为参数传入了序列化器中,比如models.py中这个类叫做Loginserializers.py中定义的类叫做Loginserializers在传入序列化器时:Loginserializers(Login,many=True)这样直接将models.py中定义的类作为参数传入了序列化器中,会导致错误TypeError: “ModelBase is n原创 2020-11-18 10:30:47 · 1142 阅读 · 0 评论 -
Django创建app应用和admin模块
首先创建一个新的apppython manage.py startapp blog_2在setting.py中注册blog_2在blog_2中创建urls.py下面各个文件的代码分别为:urls.pyfrom django.conf.urls import urlfrom blog_2 import viewsurlpatterns = [ url(r'bbb/$', views.Hello),]views.pyfrom django.http import H原创 2020-11-09 23:52:04 · 455 阅读 · 0 评论 -
Django View
class View(object): """ Intentionally simple parent class for all views. Only implements dispatch-by-method and simple sanity checking. """ http_method_names = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace']原创 2020-11-05 11:32:11 · 110 阅读 · 0 评论 -
Django的View(视图)
原文网址https://www.cnblogs.com/machangwei-8/p/11058846.html这篇文章写的真的很好,不过还博主没有授权转载,所以先把网站贴出来,大家去博客园里面看吧。原创 2020-11-05 02:18:05 · 172 阅读 · 0 评论 -
Django框架中序列化和反序列化
1.序列化DRF的核心 就是 前后端分离的核心前后端分离开发的核心:将模型转换为json 称之为 序列化将json转换为模型 称之为 反序列化1.序列化器的字段Serializer 序列化器为了得到模型里的字段,序列化器中的字段应与模型类中的字段名一致''' serializers.py '''class BookInfoSerializer(serializers.Serializer): # read_only=True 只能读 不能修改 id = serializ原创 2020-11-04 01:36:23 · 763 阅读 · 0 评论 -
Django序列化
首先先创建一个Django的项目再新建一个app输入:python manage.py startapp serialize创建一个模型,以书本出版社为例,自行迁移完成以后,再配置路由,主要讲解的是views.py,其他的不多说了。第一种方法:untitled13/serialize/views.py的配置如下:from django.db import models# Create your models here.from django.db import modelsclas原创 2020-11-03 22:54:13 · 1092 阅读 · 1 评论 -
Django-路由Routers-SimpleRouter-DefaultRouter使用方法
路由Routers对于视图集ViewSet,我们除了可以自己手动指明请求方式与动作action之间的对应关系外,还可以使用Routers来帮助我们快速实现路由信息。REST framework提供了两个routerSimpleRouterDefaultRouter1. 使用方法1) 创建router对象,并注册视图集,例如from rest_framework import routersrouter = routers.SimpleRouter()router.register(转载 2020-11-03 13:34:46 · 2178 阅读 · 0 评论 -
perform_update和update的区别
perform_update和update的区别,所到底这也是patch响应和put响应的区别。perform_update这个函数本身就是你传递什么字段参数就修改什么值 不会要求你传递所有的值put要求传递所有没有设置默认值的字段参数...原创 2020-11-02 19:04:36 · 1201 阅读 · 0 评论