-2

I'm using Django with Atom engine and when I log in to the link http://127.0.0.1:8000 it gets me a csrf error. what should I do?

BadRequest
  • 382
  • 1
  • 14
aryan
  • 1

2 Answers2

0
 For example this is my file form


 <form method="post" enctype="multipart/form-data">
            {% if makale.makale_foto %}
          <img class="img-fluid rounded" src="{{ makale.makale_foto.url }}" alt="">
              {% else %}
              <div class="alert alert-danger">Fotoğraf Eklenmemiş</div>
          {% endif %}
          {% csrf_token %} //this is csrf 
           {{ form|crispy }}
      <input type="submit" class="btn btn-info" style="width:100%" value="Kaydet">
      </form>
0

What you mean "There are many pages like views, model, URLs" ? You have wrong understanding about components (IMHO).

You should send csrftoken to server, every time you make HTTP POST request. Imagine that you have a form,,,

<form action="/" method="POST">
    <input type="text" name="name" />
    <input type="text" name="surname" />
    {% csrf_token %}  <!-- This template tag generates html "hidden" field with csrf token -->
    <input type="submit" value="click" />
</form>

If you are making Ajax Request, you must also send csrftoken on the server, there are many strategies of it. The most important is that Django has CsrfMiddleware which reads data from request.POST and request.COOKIES and compares each other. It's also possible avoid csrf protection. Read documentation carefully.

gachdavit
  • 1,223
  • 1
  • 6
  • 7