草庐IT

django-extensions

全部标签

python - ZipExtFile 到 Django 文件

我想知道是否有一种方法可以将zip文件上传到django网络服务器并将zip文件放入django数据库,而无需在此过程中访问实际文件系统(例如,将zip中的文件提取到tmp目录中,然后然后加载它们)Django提供了将python文件转为Django文件的功能,所以如果有办法将ZipExtFile转为python文件应该没问题。感谢您的帮助!Django模型:fromdjango.dbimportmodelsclassFoo:file=models.FileField(upload_to='somewhere')用法:fromzipfileimportZipFilefromdjango

python - Sentry 、乌鸦和 Django celery

现在django-sentry已经成为一个独立的服务器(而且非常棒)我正在尝试移植我的应用程序以使用它。我已经设置了一个配置了django应用程序的独立服务器tologusingdjango1.3'sloggingdictionaryconfaspertheravendocs.我似乎无法让任何celery任务登录到Sentry服务器(尽管它们确实被打印到控制台)。我不确定我应该做什么?我在我的`INSTALLED_APPS'中包含了raven.contrib.django.celery。未捕获的异常被发送到Sentry,自定义日志消息也是通过:importlogginglogger=l

python - Django 在模板中获取 ContentType

我有一个页面,其中包含许多具有不同内容类型的对象。我需要有能力评价这个对象。这是它的一个类:classScore(models.Model):user=models.ForeignKey(User)content_type=models.ForeignKey(ContentType)object_id=models.PositiveIntegerField()for_object=generic.GenericForeignKey('content_type','object_id')like=models.BooleanField(default=True)created_at=mo

python - 如何修复 django 1.5 中的 localflavor 弃用警告?

我已将现有的django1.3迁移到django1.5。一切似乎都很好。但是,当我启动pythonmanage.pyrunserver时,由于localflavor,我收到了弃用警告...\env\lib\site-packages\django\contrib\localflavor__init__.py:2:DeprecationWarning:django.contrib.localflavorisdeprecated.Usetheseparatedjango-localflavor-*packagesinstead.warnings.warn("django.contrib.l

python - Django Rest Framework 如何更新 SerializerMethodField

我有一个像这样的序列化器:classPersonSerializer(serializers.ModelSerializer):gender=serializers.SerializerMethodField()bio=BioSerializer()classMeta:model=Personfields=UserSerializer.Meta.fields+('gender','bio',)defget_gender(self,obj):returnobj.get_gender_display()我在执行GET请求时用它来显示“男”和“女”(代替“M”或“F”)。这很好用。但现在我正

python - 在 Django REST 控件序列化程序中不会自动删除空格?

模型.pyclassMsg(models.Model):content=models.CharField(max_length=1024,null=True)序列化器.pyclassMessageSerializer(serializers.ModelSerializer):classMeta:model=Msgfields=["content"]有数据:{"content":"spacetest"}和print(data)serializer=MessageSerializer(data=data)ifserializer.is_valid():serializer.save()pr

python - 由于不在 TTY 中工作,无法在 Django 中创建 super 用户

我从djangoproject.com浏览了第一个django教程,在第2部分的开头,当我运行"pythonmanage.pycreatesuperuser"时创建super用户,我收到以下消息:SuperusercreationskippedduetonotrunninginaTTY.Youcanrun`manage.pycreatesuperuser`inyourprojecttocreateonemanually.当我在运行syncdb后继续创建super用户时,我得到了相同的消息。我正在为Windows7、Django1.7.1和Python2.7.8开发Eclipse。

python - 使用 Django Rest Framework 和 IOS 应用程序时要使用哪种身份验证?

我有一个iOS应用程序,它使用由DjangoREST框架提供支持的API来存储、更新和从数据库中获取数据。我需要提供另外两个将用户数据存储在服务器上的功能:使用邮箱登录使用Facebook登录似乎有两种不同的身份验证系统可供我使用:DjangoUserAuthenticationSystemDjangoRestFrameworkAuthentication我应该如何在我的API中处理这个问题? 最佳答案 当你在iOS上使用DjangoREST框架时,除非你使用浏览器,否则标准的Django身份验证系统是不可能的。这是通过DRFaut

python - Django 模型一个外键到多个表

所以我有一个问题,我正在考虑创建一个表,该表具有到其他几个表的外键,并使用另一个字段“类型”来说明该键应该属于哪个表。classStatus(Models.model):request=models.ForeignKey("Request1","Request2","Request3")request_type=models.IntegerField()...SomestatusrelateddataclassRequest1(Models.model):...SomedataclassRequest2(Models.model):...SomeotherdataClassReques

python - Django 错误配置 : WSGI application 'myproject.wsgi.application' could not be loaded; Error importing module

我几乎全新安装了django,当我运行pythonmanage.pyrunserver时。它给我这个错误:ImproperlyConfigured:WSGIapplication'myproject.wsgi.application'couldnotbeloaded;Errorimportingmodule.设置.pyWSGI_APPLICATION='myproject.wsgi.application'wsgi.pyimportosfromdjango.core.wsgiimportget_wsgi_applicationos.environ.setdefault("DJANGO_