下記の設定は既に設定済みでしようか? Add the middleware'django.middleware.csrf.CsrfViewMiddleware' to your list of middleware classes, MIDDLEWARE_CLASSES. (It should come before CsrfResponseMiddleware if that is being used, and before any view middleware that assume that CSRF attacks have been dealt with.)
Alternatively, you can use the decoratordjango.views.decorators.csrf.csrf_protect on particular views you want to protect (see below) また Postの際に、CSRFの値を含んでいるか気になります Por iPhone On 2012/08/31, at 23:48, tonpa <oniku.wo.mog...@gmail.com> wrote: > tonpaです。 > > 早速の返信ありがとうございます。 > > 環境について不足があり申し訳ありません。 > > // パッケージ > Apache/2.2.21 > Django-1.3 > > // ディレクトリ構成 > /Sites/my_site/ > | > +----settings.py > +----urls.py > +---wsgi.py > +---media > | > +---css > +---img > +---js > +---my_app > > // apache.conf > <VirtualHost *:80> > DocumentRoot "/Sites/my_site/" > ServerName my_app.com > ErrorLog "/private/var/log/apache2/my_app-error_log" > CustomLog "/private/var/log/apache2/my_app-access_log" common > > Alias /media/ /Sites/my_site/media/ > Alias /static/ /Sites/my_site/static/ > > WSGIScriptAlias / /Sites/my_site/wsgi.py > > <Directory "/Sites/my_site/"> > AllowOverride None > Order allow,deny > Allow from all > </Directory> > </VirtualHost> > > > また、開発環境時はcontext_processorで以下のように設定しておりました。 > > // context_processor.py > import settings > > def media(request): > return { > 'MEDIA_URL': settings.MEDIA_URL, > } > > 自分がおかしいと思う点が一点ありまして、 > 先ほどにも書いた、 https://docs.djangoproject.com/en/1.3/ref/contrib/csrf/#ajax > こちらのスクリプト上で、cookieにX-CSRFTokenをセットしているように見受けられるのですが、 > > xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); > > 確認してみたところ実際のリクエストには、cookieにはX-CSRFTokenはnullとなっておりました。 > > 原因の一因となるのかすら分かりませんが、よろしくお願いします。 > > > > > > > 2012年8月31日金曜日 17時53分13秒 UTC+9 Toru Tomita: > ”403”はhttp status > codeであり、開発環境はdjangoのframeworkのwebserverで動いていたのであれば、デプロイ環境のApacheの設定におかしいところが在るのではないでしょうか? > http://ja.wikipedia.org/wiki/HTTP_403 > > どのような環境で動かされているのか不明なため、原因の推測が今案最低限、開発環境、動作環境(apacheデプロイ環境)などを記載頂かないと回答が難しいです。 > > ※技術系メーリングリストで質問方法 > http://www.hyuki.com/writing/techask.html > > > 2012/8/31 tonpa <oniku.w...@gmail.com>: > > こんにちわ > > > > 先日もお世話になったtonpaです。 > > > > django1.3で以下の用にPOSTをしたところ、403で返ってきてしまっているようです。 > > > > // post > > $.post("/detail", {id: id} , function(data) { callback }) > > > > // view > > def detail(request): > > if request.is_ajax(): > > if request.method == 'POST': > > detail = Model.objects.get(id=csrf(request.POST['id'])) > > return render_to_response('detail.html', > > {'detail': detail}, > > context_instance=RequestContext(request)) > > > > また、以下に記載されているサンプルをコピーして読み込んでおります。 > > https://docs.djangoproject.com/en/1.3/ref/contrib/csrf/#ajax > > > > 開発環境で開発中のときは期待通の動作をしておりましたが、 > > apacheにデプロイしてからは、403を返すようになってしまいました。 > > > > 原因追及にご協力いただけませんでしょうか。 > > > > よろしくお願いいたします。 > > > > > > -- > > ----------------- http://djangoproject.jp/ ----------------- > > You received this message because you are subscribed to the Google Groups > > "django-ja" group. > > To post to this group, send email to djan...@googlegroups.com > > To unsubscribe from this group, send email to > > django-ja-...@googlegroups.com > > For more options, visit this group at > > http://groups.google.com/group/django-ja > > -- > ----------------- http://djangoproject.jp/ ----------------- > You received this message because you are subscribed to the Google Groups > "django-ja" group. > To post to this group, send email to django-ja@googlegroups.com > To unsubscribe from this group, send email to > django-ja-unsubscr...@googlegroups.com > For more options, visit this group at http://groups.google.com/group/django-ja -- ----------------- http://djangoproject.jp/ ----------------- You received this message because you are subscribed to the Google Groups "django-ja" group. To post to this group, send email to django-ja@googlegroups.com To unsubscribe from this group, send email to django-ja-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-ja