Django表单模型的问题
我正在处理表单模型并获取此错误:全局名称'AdForm'未定义
在我看来,我有:
从django.template导入RequestContext,从django.http载入导入从django.shortcuts导入HttpResponse从django.contrib.auth.decorators导入重定向从django导入表单导入login_required导入表单
@login_required
def create(request):
    if request.POST:
        ad = AdForm(request.POST)
        if ad.is_valid():
            test = 'valid'
        else:
            test = 'invalid'
    else:
        test = 'none'
    template = loader.get_template('ads/create.html')
    context = RequestContext(request, {
        'test': test
    })
    return HttpResponse(template.render(context))
然而,它并没有拿起我的模型。 我认为我的模型是:
from django.db import models
from django.forms import ModelForm
TYPE_CHOICES = (
    'Image',
    'Code',
)
SIZE_CHOICES = (
    'Leaderboard',
    'Banner',
    'Skyscraper',
    'Square',
)
class Ad(models.Model):
    title = models.CharField(max_length=40)
    type = models.CharField(max_length=7)
    size = models.CharField(max_length=16)
    clicks = models.IntegerField()
    media = models.ImageField(upload_to='ads')
    link = models.URLField(null=True)
    created = models.DateTimeField(auto_now_add=True)
    expires = models.DateTimeField(null=True)
    def __unicode__(self):
        return self.name
class AdForm(ModelForm):
    class Meta:
        model = Ad
有谁知道为什么它没有选择表单模型?
谢谢你的小菜。
在您看来,您需要:
from .models import AdForm
  另外,表单通常使用forms.py ,而不是模型。 
