草庐IT

Django-pyodbc

全部标签

python - 在 Django 模板中获取文件扩展名

我有这样的模型:classFile(models.Model):name=models.CharField(max_length=45)description=models.CharField(max_length=100,blank=True)file=models.FileField(upload_to='files')我在View中获取了所有File对象,并且根据文件类型,我想打印适当的类:link或link或link在我的模板中。如何在Django模板中获取文件扩展名?我想做这样的事情:{%forfileinfiles%}{%iffile.get_extension=='pdf

python - 登录页面上的 POST 请求后在 Django 中生成 MultiValueDictKeyError

我正在尝试构建一个登录页面。我正在运行Django1.6.1。我主要关注www.fir3net.com/Django/django.html上的教程。为了方便起见,我将在这里转载很多内容。错误信息:RequestMethod:GETRequestURL:http://127.0.0.1:8000/login/DatabaseInUse:SQLite3DjangoVersion:1.6.1PythonVersion:2.7.4InstalledApplications:('django.contrib.admin','django.contrib.auth','django.contri

python - 如何按django中的计算值排序

嘿,我想在Django中根据计算值对对象进行排序...我该怎么做?这是一个基于堆栈溢出的用户配置文件模型示例,它解释了我的困境:classProfile(models.Model):user=models.ForeignKey(User)defget_reputation():...returnreputationreputation=property(get_reputation)所以,假设我想按声誉对用户进行排序。我怎么做?我知道你不能只这样做:Profile.objects.order_by("-reputation")感谢大家的帮助:) 最佳答案

python - 在 Python 中为 Django Choice 字段创建智能循环列表

所以。以下不是很“聪明”;)MONTHS=(('Jan','Jan'),('Feb','Feb'),('Mar','Mar'),('Apr','Apr'),('May','May'),('Jun','Jun'),('Jul','Jul'),('Aug','Aug'),('Sep','Sep'),('Oct','Oct'),('Nov','Nov'),('Dec','Dec'),)YEARS=(('1995','1995'),('1996','1996'),('1997','1997'),('1998','1998'),('1999','1999'),('2000','2000'),('

python - 具有唯一电子邮件的 Django auth.user

我使用django.auth系统并且我有这个:classRegisterForm(UserCreationForm):username=forms.RegexField(label="Username",max_length=30,regex=r'^[\w]+$',error_messages={'invalid':"Thisvaluemaycontainonlyletters,numbersand_characters."})email=forms.EmailField(label="Email")first_name=forms.CharField(label="Firstname

python - 如何使用 django-celery 配置 TASK_SERIALIZER

我正在使用django-celery,我想将TASK_SERIALIZER设置为JSON而不是pickle。我可以在每个方法的基础上通过改变我的任务装饰器来做到这一点@task到@task(serializer="json")但我想在全局范围内进行。设置TASK_SERIALIZER="json"在settings.py中不起作用。尝试运行importcelerycelery.conf.TASK_SERIALIZER="json"(隐含here)导致AttributeError:'module'objecthasnoattribute'conf'知道在通过django运行celery时

python - 我将如何使用 django.forms 使用模型中的行预填充选择字段?

我的表单类中有一个ChoiceField,大概是一个用户列表。我如何使用我的用户模型中的用户列表预填充它?我现在拥有的是:classMatchForm(forms.Form):choices=[]user1_auto=forms.CharField()user1=forms.ChoiceField(choices=choices)user2_auto=forms.CharField()user2=forms.ChoiceField(choices=choices)def__init__(self):user_choices=User.objects.all()forchoiceinus

python - Django 压缩迁移 : NodeNotFoundError

运行Django1.8.9。我刚刚压缩了3个应用程序的迁移并进行了部署。当./manage.pymigrate运行时,我得到了这个:django.db.migrations.graph.NodeNotFoundError:Migrationapp2.0001_squashed_0019dependenciesreferencenonexistentparentnode(u'app1',u'0001_squashed_0028')app1.0001_squashed_0028存在于磁盘上,迁移也被替换了。Django迁移系统应该具有向前迁移所需的所有信息。我能够通过以下方式解决此问题:将

python - 服务器错误时邮件请求正文以及 Django Admin

我在具有以下配置的Django中使用默认记录器:LOGGING={'version':1,'disable_existing_loggers':False,'filters':{'require_debug_false':{'()':'django.utils.log.RequireDebugFalse'}},'handlers':{'mail_admins':{'level':'ERROR','filters':['require_debug_false'],'class':'django.utils.log.AdminEmailHandler'},'console':{'level

python - Django Rest Framework Json 数据猴子修补

我遇到了像3.333333333这样的float问题,我想让它成为3.33。我不想更改此类值所在的所有Serializer类。有上千个序列化程序,它们有多个字段,其值类似于3.333333333。能否请您帮我找到猴子修补类型的解决方案,以便我编写一个类或函数来仅转换浮点值。 最佳答案 我编写了一些代码使其正常工作。我对以下文件进行了更改settings.pyREST_FRAMEWORK={'DEFAULT_RENDERER_CLASSES':('utils.renderers.PalJSONRenderer','rest_frame