输入栏不出现

时间:2018-06-27 11:49:39

标签: python django

这是我的代码form.py:

from django import forms
from .models import Category


class CategoryForm(forms.Form):
  # class Meta:
  #    model = Category
  #    fields = ('title',)
title = forms.CharField(label = 'title', max_length=100) 

这是我的view.py:

def CategoryForm(request):
 if request.method == 'POST':
     form = CategroyForm(request.POST)
     if form.is_valid():
         # category = form.save(commit = False)
         # category.title = post
         # category.save()
         return redirect('posts/create_blog.html')
 else:
    form = CategoryForm()
    template = 'posts/create_blog.html'
    context = {'form':form}
    return render(request,template,context)  

这是我的view.py:

      <form action= "CategoryForm" method = "POST" style = 'margin-top:0'>
                {% csrf_token %}
                <!--<label style='margin-left: 4%; color: gray;'>Choose Category Name</label>-->

                  {{ form.as_p }}

                <input type = 'submit' value='Submit'>

            </form>

我不太了解没有出现什么问题

我的model.py:

class Category(models.Model):
title = models.CharField(max_length=255)


def __str__(self):
    self.title 

0 个答案:

没有答案