1👍
When using a models.FileField
in Django, the key point is to declare the enctype
as following:
<form enctype="multipart/form-data" action="" method="post">
...
{% csrf_token %}
...
</form>
See here.
0👍
- Try clearing cookies and refreshing
- Check to make sure you have
django.middleware.csrf.CsrfViewMiddleware in your middleware - Check that you’re either on https or you have
CSRF_COOKIE_SECURE=False
- [Django]-Serving static files for development mode in Django
- [Django]-How would I write a CSV file populated with my sqlite3 db?
- [Django]-Web Dev. Framework for RAD Web App Dev. in Shortest Time ( Yii vs. Django )
- [Django]-Django collectstatic on S3 uploads unchanged files everytime on Heroku
0👍
First of all you should check by undoing the changes you made to the model. If the problem still persists ,then you may have made some change elsewhere. Also try it from a different device and user account(even after clearing cookies/hard reload, somethimes browsers behave unexpectedly).
You can also try answers from these links.(link 1, link 2 )
Checking the html source may help.
Also, if you are using custom django admin forms, check them again if they require any changes. Using @csrf_exempt
while trying different scenarios may help you understand, if this error is really because of csrf or there is another problem.
Also see this in django docs.
- [Django]-Formatting Time Django Template
- [Django]-Django: How to keep track of a linear (yet flexible) project management workflow?
- [Django]-Setting up Django website on a shared hosting
- [Django]-What's your favorite way to test the javascript in your djangoapp?
0👍
Same issue. Played with requires_csrf_token and csrf_protect. None worked for me.
Browser was launched in user session, and uploading file was 777 root:root in /home/username. changed file owner to user, and all worked.
So, in some scenarios, not only chmod 777, but chown username:username.
- [Django]-Use context processor only for specific application
- [Django]-What's your favorite way to test the javascript in your djangoapp?
-1👍
I faced the same issue. My problem was with the file permissions, I had to use sudo chmod 777 file
- [Django]-How to have nested url namespaces with a dynamic first part in Django
- [Django]-How to use dart sass in python
- [Django]-Django cluster deployment
- [Django]-I can't insert a footnote into the copied text
- [Django]-Django google maps