comments 등록폼 만드는데 CSRF에러가 뜨는데 해결방법을 못찾겠습니다.

666 views
Skip to first unread message

donghuna

unread,
Aug 19, 2012, 1:16:30 PM8/19/12
to djan...@googlegroups.com
1 {% load comments %} 2 <form method="POST" action="{% comment_form_target %}" class="comment_form"> 3 {% csrf_token %} 4 <dl> 5 <dt class="comment_user"> 6 {{ user.username }} 7 </dt> 8 <dd class="comment_content"> 9 {{ form.comment }} 10 <input type="submit" class="eng button" value="Comment"/> 11 </dd> 12 </dl> 13 {{ form.content_type }} 14 {{ form.object_pk }} 15 {{ form.timestamp }} 16 {{ form.security_hash }} 17 <input type="hidden" name="next" value="{{ request.get_full_path }}"/> 18 </form>

csrf_token 적어놓았는데도 계속 이런 오류가 발생합니다.ㅠ
어떻게 해야될까요 ㅠㅠ

이순연

unread,
Aug 19, 2012, 1:24:53 PM8/19/12
to djan...@googlegroups.com
실제 브라우저에서 값이 토큰이 출력되는지 확인하셨는지요?

2012년 8월 20일 오전 2:16, donghuna <dong...@gmail.com>님의 말:

--
Google 그룹스 'Django-ko' 그룹에 가입했으므로 본 메일이 전송되었습니다.
웹에서 이 토론을 보려면 https://groups.google.com/d/msg/django-ko/-/0tOpErF5dvAJ을(를) 방문하세요.
이 그룹에 게시하려면 djan...@googlegroups.com(으)로 이메일을 보내세요.
그룹에서 탈퇴하려면 django-ko+...@googlegroups.com로 이메일을 보내주세요.
더 많은 옵션을 보려면 http://groups.google.com/group/django-ko?hl=ko에서 그룹을 방문하세요.



--


-------------------------


donghuna

unread,
Aug 19, 2012, 1:46:14 PM8/19/12
to djan...@googlegroups.com
제가 웹공부한지가 얼마 안되어서 브라우저에서 토큰이 출력되는지의 여부를 확인할줄 모릅니다. ㅠㅠ
단순히이런 에러가 보안상 생기는 문제여서 post 하기전에 <form>바로 아래에 {% csrf_token %}을 적어주던지,
view쪽에서 @csrf_exempt를 메소드 위에 적어주는것으로 알고 있었거든요..

2012년 8월 20일 월요일 오전 2시 24분 53초 UTC+9, 순연 이 님의 말:

이순연

unread,
Aug 19, 2012, 1:49:50 PM8/19/12
to djan...@googlegroups.com
네. 에러 출력내용을 볼 수 있을까요?

2012년 8월 20일 오전 2:46, donghuna <dong...@gmail.com>님의 말:
웹에서 이 토론을 보려면 https://groups.google.com/d/msg/django-ko/-/4zcUSpn75pYJ을(를) 방문하세요.

이 그룹에 게시하려면 djan...@googlegroups.com(으)로 이메일을 보내세요.
그룹에서 탈퇴하려면 django-ko+...@googlegroups.com로 이메일을 보내주세요.
더 많은 옵션을 보려면 http://groups.google.com/group/django-ko?hl=ko에서 그룹을 방문하세요.

donghuna

unread,
Aug 19, 2012, 1:52:55 PM8/19/12
to djan...@googlegroups.com

Forbidden (403)

CSRF verification failed. Request aborted.

Help

Reason given for failure:

    CSRF token missing or incorrect.
    

In general, this can occur when there is a genuine Cross Site Request Forgery, or when Django's CSRF mechanism has not been used correctly. For POST forms, you need to ensure:

  • Your browser is accepting cookies.
  • The view function uses RequestContext for the template, instead of Context.
  • In the template, there is a {% csrf_token %} template tag inside each POST form that targets an internal URL.
  • If you are not using CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag, as well as those that accept the POST data.

You're seeing the help section of this page because you have DEBUG = True in your Django settings file. Change that to False, and only the initial error message will be displayed.

You can customize this page using the CSRF_FAILURE_VIEW setting.

이순연

unread,
Aug 19, 2012, 1:58:24 PM8/19/12
to djan...@googlegroups.com
네..
브라우저에서 포스팅하기전 '소스보기'를 실행하여 form에 토큰이 정상적으로 출력되어 있는지 확인할 필요가 있는 것 같습니다.

그리고 settings.py의 미들웨어 클래스에 아래와 같이 CsrfViewMiddleware가 들어가 있는지도요.

MIDDLEWARE_CLASSES = (

    .....

    'django.middleware.csrf.CsrfViewMiddleware',

    ...

}



2012/8/20 donghuna <dong...@gmail.com>

--
Google 그룹스 'Django-ko' 그룹에 가입했으므로 본 메일이 전송되었습니다.
웹에서 이 토론을 보려면 https://groups.google.com/d/msg/django-ko/-/mKbLURqPjWMJ을(를) 방문하세요.

이 그룹에 게시하려면 djan...@googlegroups.com(으)로 이메일을 보내세요.
그룹에서 탈퇴하려면 django-ko+...@googlegroups.com로 이메일을 보내주세요.
더 많은 옵션을 보려면 http://groups.google.com/group/django-ko?hl=ko에서 그룹을 방문하세요.

donghuna

unread,
Aug 19, 2012, 2:12:52 PM8/19/12
to djan...@googlegroups.com
소스보기로 보니까 마지막에 request.get_full_path 변수값이 안들어왔네요..
답변 정말 감사합니다!! ^^



2012년 8월 20일 월요일 오전 2시 58분 24초 UTC+9, 순연 이 님의 말:

donghuna

unread,
Aug 19, 2012, 7:52:59 PM8/19/12
to djan...@googlegroups.com
에러는 계속 뜨네요 ㅠㅠㅠ

2012년 8월 20일 월요일 오전 3시 12분 52초 UTC+9, donghuna 님의 말:
Reply all
Reply to author
Forward
0 new messages