草庐IT

django-csrf

全部标签

python - 我的第一个网络应用程序 (Python) : use CGI, 还是像 Django 这样的框架?

我不想在细节上给大家带来负担,但基本上我是一名没有Web开发经验的二年级compsci学生。基本上,我想创建一个小型“网络应用程序”,它从html表单接收输入,让python脚本执行一些计算,然后在浏览器中重新显示这些结果。截至目前,我已经构建了表单和脚本。但是,当我尝试测试表单时,我的浏览器并没有运行脚本,而是尝试下载它。据我了解,这是一个cgi脚本问题,我必须创建一个Web服务器才能测试该脚本。这是我被困住了。我对网络服务器以及如何设置它们知之甚少。最重要的是,我听说GCI脚本已成为过去,需要大量开销才能正常运行。这引出了我的问题。我如何着手完成我的应用程序并测试我的cgi脚本?我

python - 如何自定义 Django Rest Framework 序列化器输出?

我有一个像这样的Django模型:classWindowsMacAddress(models.Model):address=models.TextField(unique=True)mapping=models.ForeignKey('imaging.WindowsMapping',related_name='macAddresses')还有两个序列化器,定义为:classWindowsFlatMacAddressSerializer(serializers.Serializer):address=serializers.Field()classWindowsCompleteMappi

python - Django Celery 任务记录

我在我正在处理的Django项目中设置了Celery。我想将celery任务的日志记录与其余的celery日志(celerycam、celerybeat等)分开。根据Celery文档(http://docs.celeryproject.org/en/latest/userguide/tasks.html#logging),我似乎应该能够为“celery.task”定义一个Django记录器,它应该执行此操作。但是,当我这样做时,日志中没有显示任何内容。如果我创建一个通用的“celery”记录器,一切都会显示出来,这意味着这可能与记录器的名称有关。我在这里错过了什么?有什么办法可以做到这

python - Django - 查询给出一列不等于同一模型中另一列的行

我的模型有3个字段classTable(models.Model):in_time=models.DateTimeField(null=True,blank=True)actual_time=models.DateTimeField(null=True,blank=True)我想以这种方式获取结果:select*fromTablewherein_time>'2013-12-3100:00:00'andin_time!=actual_time谁能帮我完成这个result=Table.objects.filter(in_time__gte='2013-12-3100:00:00')

python - Django修改密码问题,super(type, obj) : obj must be an instance or subtype of type

我的changepassword表单有一些问题,它继续给我同样的错误:super(type,obj):objmustbeaninstanceorsubtypeoftype这是我的表格:classPasswordChangeForm(forms.Form):current_password=forms.CharField(label=u'CurrentPassword',widget=forms.PasswordInput(render_value=False))new_password=forms.CharField(label=u'NewPassword',widget=forms.

python - 从 Django shell 上传图像

我需要将一堆图像导入Django应用程序。我正在shell中进行测试,但在尝试保存图像时无法解决此错误:File"/lib/python3.3/codecs.py",line301,indecode(result,consumed)=self._buffer_decode(data,self.errors,final)UnicodeDecodeError:'utf-8'codeccan'tdecodebyte0xffinposition0:invalidstartbyte模型:importuuidfromdjango.dbimportmodelsfromtaggit.managersi

python - Django:有没有办法让 ManyToManyField 中的 "through"模型与包含 ManyToManyField 的模型在不同的应用程序中?

假设我有两个Django应用程序:competitions-将处理比赛数据entries-将处理与让参赛者参加比赛相关的功能在比赛应用程序中,我有一个代表比赛部分的模型:classDivision(models.Model):competition=models.ForeignKey(Competition)discipline=models.CharField(max_length=1,choices=DISCIPLINE_CHOICES)age_group=models.ForeignKey(AgeGroup)participants=models.ManyToManyField(

python - Django 自定义文件存储系统

我有一个自定义存储importosfromdjango.core.files.storageimportStorageclassAlwaysOverwriteFileSystemStorage(Storage):defget_available_name(self,name):"""DirectlyReturnsafilenamethat'sfromwhatuserinput."""ifself.exists(name):#Removetheexistingfileos.remove(name)#Returntheinputnameasoutputreturnname我想知道我应该把他

python - 在 Django 管理控制台中显示属性的勾号和十字图标

在Django管理中,如果字段是BooleanField或NullBooleanField,Django将显示漂亮的“开”或“关”图标,而不是True或False。现在,我的模型中实际上并没有BooleanField,因为我确实有一个属性fior,我想显示图标,但是当我尝试这样做时,Django尖叫着'SomeAdmin.list_filter[0]'指的是'is_activated',它不指代字段。是否可以在不对Django进行太多攻击的情况下为该字段显示那些漂亮的小图标。谢谢 最佳答案 您不想使用list_filter。您要找的

python - 如何将错误消息附加到 django 中的 form.non_field_errors?

我有一个包含多个字段的表单。我对每个字段都有单独的验证检查,通过表单验证完成。然而,在将用户重定向到不同的View之前,我还需要检查是否填写了几个字段。我希望我能以某种方式将错误附加到forms.non_field_errors,因为它不是针对特定字段的,但我不确定正确的语法是什么。我上网查了一下,发现..form.errors['__all__']=form.error_class(["errormsg"])这会显示错误消息,但它似乎也弄乱了其他页面,如果我单击其他任何内容,就会显示错误消息。我试过了form._errors[NON_FIELD_ERRORS]=form.error_