These are chat archives for django/django

26th
Dec 2017
:]
@elcolie
Dec 26 2017 02:45
@prajjuwan-194 Yes. Suspect line.
mohammadreza
@ultra2mh
Dec 26 2017 09:45

guys i have login form in angular 4 how should i use django CSRF_token for this form

without csrf i have this error
Forbidden (403) CSRF verification failed. Request aborted. Help Reason given for failure: CSRF token missing or incorrect.

mohammadreza
@ultra2mh
Dec 26 2017 13:40
any ideaa?
:]
@elcolie
Dec 26 2017 13:45
@ultra2mh Use Django REST
mohammadreza
@ultra2mh
Dec 26 2017 13:45
why
:]
@elcolie
Dec 26 2017 13:45
CSRF token it comes with template
I use ReactJS consumes my Django RESTful APIs
Anybody here using gitlab-ci?
I am having problem and unable to solve.
Riadh
@KWFE
Dec 26 2017 22:19
Hi
anyone is here !
Roel
@roelzkie15
Dec 26 2017 23:17

@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.