Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6384211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:44:53+00:00 2026-05-25T02:44:53+00:00

I am working on form models and get this error: global name ‘AdForm’ is

  • 0

I am working on form models and get this error:
global name ‘AdForm’ is not defined

In my view I have:

from django.template import RequestContext, loader
from django.http import HttpResponse
from django.shortcuts import redirect
from django.contrib.auth.decorators import login_required
from django import forms

@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))

However it is not picking up my model. My model in my view is:

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

Does anyone know why it is not picking up the form model?

Thanks from a noob.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:44:54+00:00Added an answer on May 25, 2026 at 2:44 am

    At the top of your view, you need:

    from .models import AdForm
    

    Also, forms usually go in forms.py, not with the models.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to get a form working in Internet Explorer. I see that when
I'm trying to get a simple search form working in my RoR site. I've
Form validation for check boxes only seems to be working in IE....? Anyone have
I've been struggling for quite a while to get this feature working: I want
I'm having problems binding on a form with multiple models being submitted. I have
I cannot seem to get a nested form to generate in a rails view
I'm working on an application developed using Zend Framework. I have defined relationships in
I am working through the Ruby-on-Rails3 Tutorial Chapter 8. I have created a form
This post extends the error while submitting data in the form django model.py from
So I have this demo project almost completely working. public class Project { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.