{"id":17188857,"url":"https://github.com/imerica/django-react-csrftoken","last_synced_at":"2025-04-13T19:22:55.391Z","repository":{"id":57213219,"uuid":"69848811","full_name":"iMerica/django-react-csrftoken","owner":"iMerica","description":"A drop-in React component for submitting forms with a Django CSRF middleware token.","archived":false,"fork":false,"pushed_at":"2019-11-21T09:08:54.000Z","size":14,"stargazers_count":31,"open_issues_count":2,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T10:17:52.978Z","etag":null,"topics":["django","django-csrf-middleware","npm","npm-module","npm-package","react","reactjs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/django-react-csrftoken","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iMerica.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-03T07:18:22.000Z","updated_at":"2025-03-02T08:52:31.000Z","dependencies_parsed_at":"2022-08-24T21:41:55.039Z","dependency_job_id":null,"html_url":"https://github.com/iMerica/django-react-csrftoken","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iMerica%2Fdjango-react-csrftoken","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iMerica%2Fdjango-react-csrftoken/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iMerica%2Fdjango-react-csrftoken/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iMerica%2Fdjango-react-csrftoken/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iMerica","download_url":"https://codeload.github.com/iMerica/django-react-csrftoken/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248766688,"owners_count":21158302,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-csrf-middleware","npm","npm-module","npm-package","react","reactjs"],"created_at":"2024-10-15T01:10:03.747Z","updated_at":"2025-04-13T19:22:55.364Z","avatar_url":"https://github.com/iMerica.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DjangoCSRFToken\n\n![https://circleci.com/gh/iMerica/django-react-csrftoken/](https://circleci.com/gh/iMerica/django-react-csrftoken.png?style=shield)\n\nA drop-in React component for submitting forms with a Django CSRF middleware token.\n\n\n## Installation\n\n    npm install --save django-react-csrftoken\n\n\n## Usage\n\n```javascript\n\nimport React from 'react';\nimport DjangoCSRFToken from 'django-react-csrftoken'\n\nclass MyLoginForm extends React.Component {\n  render(){\n    return (\n      \u003cdiv className=\"container\"\u003e\n          \u003cform\u003e\n            \u003cDjangoCSRFToken/\u003e\n            // email\n            // password\n            // submit button\n          \u003c/form\u003e\n      \u003c/div\u003e\n    )\n  }\n}\n```\n\n## CSRF Cookie and React\n\nBecause react renders elements dynamically, Django might not set a CSRF token cookie if you render a form using react.\nThis is described in [the Django docs](https://docs.djangoproject.com/en/1.11/ref/csrf/):\n\u003e If your view is not rendering a template containing the csrf_token template tag, Django might not set the CSRF token cookie. This is common in cases where forms are dynamically added to the page. To address this case, Django provides a view decorator which forces setting of the cookie: ensure_csrf_cookie().\n\nTo fix this problem add the decorator mentioned above to your views:\n```python\n\nfrom django.views.decorators.csrf import ensure_csrf_cookie\n\n@ensure_csrf_cookie\ndef register_view(request):\n    // ...\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimerica%2Fdjango-react-csrftoken","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimerica%2Fdjango-react-csrftoken","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimerica%2Fdjango-react-csrftoken/lists"}