2011-07-28 8 views
11

私は最終的に私のフォームを検証し、投稿し、必要なページにリダイレクトするようにしました。レンダリング中にAttributeErrorが発生しました。 'WSGIRequest'オブジェクトに 'get'属性がありません

キャッチはAttributeErrorレンダリング中:私は私はこのエラーを取得する形でページに戻ったときに今、私の問題がある「WSGIRequest」オブジェクトには、属性動作するようにそれを復元する唯一の方法は思え

「を取得」を持っていません前に動作していなかったものを置き換えるforms.pyを削除することです。働いているものを加えて、それを一度働かせることができます。何がこの問題を引き起こす可能性がありますか?

FORMS:

class LeadSubmissionForm(forms.ModelForm): 
    """ 
    A simple default form for messaging. 
    """ 
    class Meta: 
     model = Lead 
     fields = ( 
      'parent_or_student', 'attending_school', 'how_much', 'year_of_study', 'zip_code', 'email_address', 'graduate_year', 'graduate_month', 'email_loan_results' 
     ) 

閲覧数:

@render_to("lender/main_views/home.html") 
def home(request): 
    if request.method == 'POST': 
     form = LeadSubmissionForm(request.POST) 
     if form.is_valid(): 
      form.save() 
      return HttpResponseRedirect(reverse("search_results")) 
    else: 
     form = LeadSubmissionForm(request) 

    testimonials = Testimonial.objects.filter(published=True)[:3] 
    return {'lead_submission_form':form, 
     'testimonials': testimonials,} 

MODELS:

class Lead(TitleAndSlugModel): 
    """ 
    A lead submitted through the site (i.e. someone that has at-least submitted the search form 
    """ 

    PARENT_OR_STUDENT = get_namedtuple_choices('PARENT_OR_STUDENT', (
     (0, 'PARENT', 'Parent'), 
     (1, 'STUDENT', 'Student'), 
    )) 
    YEARS_OF_STUDY = get_namedtuple_choices('YEARS_OF_STUDY', (
     (0, 'ONE', '1'), 
     (1, 'TWO', '2'), 
     (2, 'THREE', '3'), 
     (3, 'FOUR', '4'), 
    )) 

    parent_or_student = models.PositiveIntegerField(choices=PARENT_OR_STUDENT.get_choices(), default=0) 
    attending_school = models.ForeignKey(School) 
    how_much = models.DecimalField(max_digits=10, decimal_places=2) 
    year_of_study = models.PositiveIntegerField(choices=YEARS_OF_STUDY.get_choices(), default=0) 
    zip_code = models.CharField(max_length=8) 
    email_address = models.EmailField(max_length=255) 
    graduate_year = models.IntegerField() 
    graduate_month = models.IntegerField() 
    email_loan_results = models.BooleanField(default=False) 

    def __unicode__(self): 
     return "%s - %s" % (self.email_address, self.attending_school) 

再び任意のヘルプは大きな助けです。ありがとうございました!!

答えて

20

request.method == 'GET'のときにLeadSubmissionFormをインスタンス化するときにリクエストを渡す必要はありません。数行のコードを保存するには

、あなたも行うことができます:あなたを助け

@render_to("lender/main_views/home.html") 
def home(request): 
    form = LeadSubmissionForm(request.POST or None) 
    if request.method == 'POST': 
     if form.is_valid(): 
      form.save() 
      return HttpResponseRedirect(reverse("search_results")) 
    testimonials = Testimonial.objects.filter(published=True)[:3] 
    return {'lead_submission_form':form, 'testimonials': testimonials} 

希望を。

+0

それでした!そんなにBrandonありがとう! – tjoenz

関連する問題