Thursday, February 24, 2011

Re: CSRF verification failed. Request aborted.


Hi,

instead of @csrf_protect use  @csrf_exempt if you dont need csrf and it will work

--ankit

On Thu, Feb 24, 2011 at 2:50 PM, luca72 <lucaberto@libero.it> wrote:
Thanks for your reply:
this is the middleware:
MIDDLEWARE_CLASSES = (
   'django.middleware.common.CommonMiddleware',
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.middleware.csrf.CsrfViewMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
   'django.contrib.messages.middleware.MessageMiddleware',
   'django.middleware.csrf.CsrfViewMiddleware',
)

the view now  is this:
@login_required
@csrf_protect
def inserisco(request):
   import os, time
   from django.core.files import File
   request.session.set_expiry(0)
   titolo = "Inserisci File"
   if request.user.is_superuser:
       if request.method == 'POST':
           form = Form_inserisco(request.POST, request.FILES)
           if form.is_valid():
               nome_f = form.cleaned_data['nome']
               nome = nome_f.name
               l = nome_f.size
               mio_file = open(nome,'wb')
               for chunk in nome_f.chunks():
                   mf = mio_file.write(chunk)
               mio_file.close()
               lunghezza = (str(l)+' bytes')
               ora_data = time.ctime()
               info = form.cleaned_data['info']
               descrizione = form.clened_data['descrizione']
               salvo_tipi = Finale(nome=nome, dimensione=lunghezza,
data_ora=ora_data, info=info, descrizione=descrizione)
               salvo_tipi.save()
               salv_corr = """<script type="text/javascript">
                           {alert('File salvato correttamente')}
                           </script>"""
               n_c = mark_safe(salv_corr)
               c = {'form':form, 'titolo':titolo, 'n_c':n_c}
               #c.update(csrf(request))
               return
render_to_response('inserisco.html',c,context_instance=RequestContext(request))
i get the same error what is wrong?

Thanks

Luca

On 24 Feb, 10:00, Kenneth Gonsalves <law...@thenilgiris.com> wrote:
> On Thu, 2011-02-24 at 00:54 -0800, luca72 wrote:
> > I get CSRF verification failed. Request aborted. after the submit
>
> you have to use RequestContext if you are using csrf - also make sure
> csrf middleware is loaded.
> --
> regards
> KGhttp://lawgon.livejournal.com
> Coimbatore LUG roxhttp://ilugcbe.techstud.org/

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment