Python 将DateTImeField更改为隐藏在django中

Python 将DateTImeField更改为隐藏在django中,python,html,django,forms,Python,Html,Django,Forms,我有一个django表单,有三个字段。其中两个需要由用户输入并存储在我的数据库中。DateTimeField是自动生成的。当我在主页中显示表单时,所有字段都在那里,如何隐藏DateTimeField 这是我的密码: models.py from django.db import models from datetime import datetime # Create your models here. class Post(models.Model): title = models.C

我有一个django表单,有三个字段。其中两个需要由用户输入并存储在我的数据库中。DateTimeField是自动生成的。当我在主页中显示表单时,所有字段都在那里,如何隐藏DateTimeField

这是我的密码:

models.py

from django.db import models
from datetime import datetime
# Create your models here.
class Post(models.Model):
    title = models.CharField(max_length = 100)
    body = models.TextField()
    dateCreated = models.DateTimeField(default=datetime.now, blank=True, )

    def __str__(self):
        return self.title
class Post(models.Model):
    title = models.CharField(max_length = 100)
    body = models.TextField()
    dateCreated = models.DateTimeField(default=datetime.now, blank=True, )

    def __str__(self):
        return self.title
forms.py

from django import forms
from .models import Post #this is the name of the model
class PostForm(forms.ModelForm):
    class Meta:
        model = Post
models.py

from django.db import models
from datetime import datetime
# Create your models here.
class Post(models.Model):
    title = models.CharField(max_length = 100)
    body = models.TextField()
    dateCreated = models.DateTimeField(default=datetime.now, blank=True, )

    def __str__(self):
        return self.title
class Post(models.Model):
    title = models.CharField(max_length = 100)
    body = models.TextField()
    dateCreated = models.DateTimeField(default=datetime.now, blank=True, )

    def __str__(self):
        return self.title
Html代码

<form method="POST" action=""> {% csrf_token %}
{{form.as_p}}

<input type='submit' value='Join' class = 'btn'>
</form>
{%csrf\u令牌%}
{{form.as_p}}

:

:

:


您根本不需要在表单中显示
dateCreated
字段。这是一个内部数据,不应向用户公开:

class PostForm(forms.ModelForm):
    class Meta:
        model = Post
        fields = ('title', 'body', )

您根本不需要在表单中显示
dateCreated
字段。这是一个内部数据,不应向用户公开:

class PostForm(forms.ModelForm):
    class Meta:
        model = Post
        fields = ('title', 'body', )

您根本不需要在表单中显示
dateCreated
字段。这是一个内部数据,不应向用户公开:

class PostForm(forms.ModelForm):
    class Meta:
        model = Post
        fields = ('title', 'body', )

您根本不需要在表单中显示
dateCreated
字段。这是一个内部数据,不应向用户公开:

class PostForm(forms.ModelForm):
    class Meta:
        model = Post
        fields = ('title', 'body', )