13👍
✅
If you have set the CSRF_COOKIE_SECURE
to be True
in your settings file, then the cookie will be marked as “secure” and therefore will need an HTTPS connection.
Which is why you receive that error.
For more information here.
7👍
I modify urls.py
If you manage your routes in urls.py, you can wrap your desired routes with csrf_exempt() to exclude them from the CSRF verification middleware.
from django.conf.urls import patterns, url
from django.views.decorators.csrf import csrf_exempt
from . import views
urlpatterns = patterns('',
url(r'^object/$', csrf_exempt(views.ObjectView.as_view())),
...
)
In views.py
class ObjectView(CreateView):
def post(self, request):
if request.method == 'POST':
#enter you view
- Django DateTimeField says 'You are 5.5 hours ahead of server time.'
- How to have Accent-insensitive filter in django with postgres?
- Why does JSON returned from the django rest framework have forward slashes in the response?
- DeleteView with a dynamic success_url dependent on id
1👍
I found the solution here:
Django Rest Framework remove csrf
I use in some parts of the system the DRF and maybe it was generating the CSRF error and ignoring the csrf_exempt decorator.
- Django_auth_ldap no module named ldap
- Django: use render_to_response and set cookie
- How to test a model that has a foreign key in django?
- How to have Accent-insensitive filter in django with postgres?
- Do I need to close connection in mongodb?
- What does 'name__iexact' mean in django model filters?
- Django Admin, accessing reverse many to many
- Failed: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it
- Django's annotate Count with division returns integer instead of float
Source:stackexchange.com