2011-11-10 12 views
-1

これは私のviews.pyです:奇妙なDjangoのエラー

# Create your views here. 

from django.http import HttpResponseRedirect 
from django.shortcuts import render_to_response 
from django.db import models 

    from display.forms import CodeForm 
    from display.forms import CodeFormSet 
    from ExamPy.questions.models import QuestionBase 


    def codepost(request): 
     if request.method == 'POST': 
      form = CodeFormSet(request.POST) 
      if form.is_valid(): 
       titles = [] 
       for i in range(0, self.total_form_count()): 
          form = self.forms[i] 
          title = form.cleaned_data['title'] 
          if title in titles: 
           raise forms.ValidationError("Articles in a set must have distinct titles.") 
           titles.append(title) 
       return render_to_response('quesdisplay.html') 
     else: 
      form = CodeFormSet() 

     return render_to_response('quesdisplay.html', {'form':form}) 

私は、送信ボタンをクリックするとこのように、それはそれで任意のフォームなしquesdisplay.htmlを表示する必要があります。でも、存在しない連絡先ページに私を連れて行っています。

エラー:私はこの中で「接触」と呼ばれるものの痕跡がないので、このが、そのことはできませんをデバッグするためにすべての可能な方法を試してみた

The current URL, contact/, didn't match any of these. 

編集:

/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py:101: UserWarning: A {% csrf_token %} was used in a template, but the context did not provide the value. This is usually caused by not using RequestContext. 
    warnings.warn("A {% csrf_token %} was used in a template, but the context did not provide the value. This is usually caused by not using RequestContext.") 
[10/Nov/2011 05:34:17] " 
+0

あなたはurls.py.で「コンタクト」のエントリをチェックしまし – danihp

+0

はい。私はした。連絡先の痕跡はありません。テンプレート内でさえも。テンプレートは "。" – Hick

+0

'連絡先'に 'quesdisplay.html'をチェックしましたか?あなたの警告に「連絡先」は表示されません。あなたはミックスの問題ですか? – danihp

答えて

3

前のコメントで見られるように、RequestContextのはあなたの問題を解決する使用して: これは私が取得警告です。私たちが読むことができたようhttps://docs.djangoproject.com/en/dev/ref/contrib/csrf/#how-to-use-it

:ここ

はcsrf_tokenについてのドキュメントです

Use RequestContext, which always uses 'django.core.context_processors.csrf' (no matter what your TEMPLATE_CONTEXT_PROCESSORS setting). If you are using generic views or contrib apps, you are covered already, since these apps use RequestContext throughout.

だからここに、どちらのcontribアプリ、我々は一般的なビューを使用していないようです。 これは、Csrf保護がDjangoで動作するようなので、RequestContextを渡すために必要なものです。

from django.core.context_processors import csrf 
from django.shortcuts import render_to_response 

def my_view(request): 
    c = {} 
    c.update(csrf(request)) 
    # ... view code here 
    return render_to_response("a_template.html", c) 

または

from django.views.generic.simple import direct_to_template 

def app_view(request):    
    return direct_to_template(request, 'app_template.html', app_data_dictionary) 

または

from django.shortcuts import render_to_response 
from django.template import RequestContext 

def app_view(request): 
    return render_to_response('app_template.html', 
           app_data_dictionary, 
           context_instance=RequestContext(request)) 

また、ドキュメントはについて語っ:エクストラ/ csrf_migration_helper.pyスクリプト。 あなたのケースのために有用であるように思わ:)

はそれがお役に立てば幸いです。)