These are chat archives for django/django
guys i have login form in angular 4 how should i use django CSRF_token for this form
without csrf i have this error
CSRF verification failed. Request aborted.
Reason given for failure:
CSRF token missing or incorrect.
@ultra2mh you can't use django traditional server template rendering in angular since there is a lot of conflict and may be hard to maintain. But there is a popular and best practices in doing so.
Separate Backend and Frontend
First, Let only your django (backend) handle data from any request made from the client (GET, POST, PUT, PATCH, DELETE etc.), in other words limit your backend for data processing only and don't use it to render any templates.
Secondly, Leave the UI/Frontend to the client side (Angular), use angular http requests (ajax call), You may question how do we handle such request in the backend or how do we extract the json data, the answer is django-restframework it has many capabilities and features how to handle any client side http request and response in an easy way, here is the link DRF, it has a great request response mechanism perfect for any djangular applications.
Many developers recommend this approach since server and client side is highly decoupled it is easier to maintain your angular application this way rather than mixing angular template to django template.