Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 绕过表单字段django的验证_Python_Django - Fatal编程技术网

Python 绕过表单字段django的验证

Python 绕过表单字段django的验证,python,django,Python,Django,我试图绕过“视频”的必填字段,但很难做到这一点。如有任何建议,将不胜感激 这是我的models.py,希望有助于了解如何进行此操作 class PostForm(forms.ModelForm): description = forms.CharField(widget=PagedownWidget(show_preview=False)) class Meta: mo

我试图绕过“视频”的必填字段,但很难做到这一点。如有任何建议,将不胜感激

这是我的models.py,希望有助于了解如何进行此操作

            class PostForm(forms.ModelForm):
                description = forms.CharField(widget=PagedownWidget(show_preview=False))
                class Meta:
                    model = Post
                    fields = [
                        'title',
                        'image',
                        'video',
                        'description',
                        'public',
                        'tags',
                        ]
从它看起来应该支持空现在自版本0.3,我建议尝试

            from django.db import models

            from django.db.models import Count, QuerySet, F
            from django.utils import timezone
            from django.conf import settings
            from django.contrib.contenttypes.models import ContentType
            from django.core.urlresolvers import reverse
            from django.db.models.signals import pre_save
            from django.utils.text import slugify
            from markdown_deux import markdown
            from django.utils.safestring import mark_safe
            from embed_video.fields import EmbedVideoField
            from taggit.managers import TaggableManager

            from comments.models import Comment

            def upload_location(instance, filename):
                return "%s/%s" %(instance.slug, filename)


            class Post(models.Model):
                user = models.ForeignKey(settings.AUTH_USER_MODEL, default=1 )
                title = models.CharField(max_length=75)
                slug = models.SlugField(unique=True)
                video = EmbedVideoField()
                image = models.ImageField(
                        upload_to=upload_location,
                        null=True,
                        blank=True,
                        width_field="width_field",
                        height_field="height_field")
                height_field = models.IntegerField(default=0)
                width_field = models.IntegerField(default=0)
                description = models.TextField()
                tags = TaggableManager()
                public = models.BooleanField(default=False)
                updated = models.DateTimeField(auto_now_add=False, auto_now=True)
                created = models.DateTimeField(auto_now_add=True, auto_now=False)


                def __str__(self):
                    return self.title

                def get_absolute_url(self):
                    return reverse("posts:detail", kwargs={"slug": self.slug})

                class Meta:
                    ordering = ["-created", "-updated" ]

                def get_markdown(self):
                    description = self.description
                    markdown_text = markdown(description)
                    return mark_safe(markdown_text)

                @property
                def comments(self):
                    instance = self
                    qs = Comment.objects.filter_by_instance(instance)
                    return qs

                @property
                def get_content_type(self):
                    instance = self
                    content_type = ContentType.objects.get_for_model(instance.__class__)
                    return content_type


            def create_slug(instance, new_slug=None):
                    slug = slugify(instance.title)
                    if new_slug is not None:
                        slug = new_slug
                    qs = Post.objects.filter(slug=slug).order_by("-id")
                    exists = qs.exists()
                    if exists:
                        new_slug = "%s-%s" %(slug, qs.first().id)
                        return create_slug(instance, new_slug=new_slug)
                    return slug



            def pre_save_post_receiver(sender, instance, *args, **kwargs):
                if not instance.slug:
                    instance.slug = create_slug(instance)


            pre_save.connect(pre_save_post_receiver, sender=Post)
文档说它应该像一个URL字段一样工作,所以您只需要标准符号就可以了


祝你好运

我目前正在使用django embed video,它要求提供视频的url,但要求填写表单。您的模型字段是否允许视频字段为
空白
和/或
?模型表单将遵循对模型本身设置的限制。我继续并添加了my models.py。让我知道你的想法。成功了,谢谢!我最初看到的是required=False,但没有结果。再次感谢。
video = EmbedVideoField(null=True,blank=True)