在Django表单中,如何使字段禁用格式符号?

时间:2019-05-31 02:41:52

标签: django django-forms django-templates django-views

我希望表单标题,说明和子句中不包含符号,该怎么做?

Models.py

class Post(models.Model):
title = models.CharField(max_length=60)
description = models.CharField(max_length=160, null=True)
slug = models.SlugField(max_length=60, unique=True,)

Views.py

class PostCreateView(LoginRequiredMixin, CreateView):
template_name = 'posts/post_form.html'
form_class = PostCreateForm

def form_valid(self, form):
    form.instance.author = self.request.user
    return super().form_valid(form)

Forms.py

class PostCreateForm(forms.ModelForm):
description = forms.CharField(widget=forms.Textarea, max_length=60,)

class Meta:
    model = Post
    fields = ['title', 'description', 'slug',]

在我的模板视图中

    <div id="div_id_title" class="form-group">
  <label for="id_title" class="col-form-label  requiredField">
    Title<span class="asteriskField">*</span>
  </label>
  <div class="">
    <input type="text" name="title" maxlength="60" class="textinput textInput form-control" required id="id_title">
  </div>
</div>
<div id="div_id_description" class="form-group">
  <label for="id_description" class="col-form-label  requiredField">
    Description<span class="asteriskField">*</span>
  </label>
  <div class="">
    *Min 50 characters, Max 160 characters.
      <textarea name="description" cols="40" rows="10" maxlength="160" class="textarea form-control" required
        id="id_description"></textarea>
  </div>........
</div>........

django 2.2

0 个答案:

没有答案