如何从model + ModelForm获取文本区域? [英] How can I get a textarea from model+ModelForm?

查看:82
本文介绍了如何从model + ModelForm获取文本区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

models.py =>

models.py=>

from django.db import models
from django.forms import ModelForm
from datetime import date
import datetime
from django import forms
from django.forms import Textarea

class Post(models.Model):
    title = models.CharField(max_length=100)
    content = models.TextField()
    created = models.DateField(auto_now_add=True)
    modified = models.DateField(auto_now_add=True)

    def __unicode__(self):
        return self.title

class PostModelForm(ModelForm):
    class Meta:
        model = Post

但是我得到的文字输入不是models.TextField()的textarea.这是CSS的原因吗?

But I get a text input not textarea for models.TextField(). Is that a reason of css?

推荐答案

我认为这

I think this section in the documentation should be useful to solve the problem.

from django.forms import ModelForm, Textarea

class PostModelForm(ModelForm):
    class Meta:
        model = Post
        widgets = {
            'content': Textarea(attrs={'cols': 80, 'rows': 20}),
        }

这篇关于如何从model + ModelForm获取文本区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆