{"id":22916734,"url":"https://github.com/chanmo/django-react","last_synced_at":"2025-09-06T01:39:05.641Z","repository":{"id":78745252,"uuid":"491028256","full_name":"ChanMo/django-react","owner":"ChanMo","description":"An easy way to integrate React with Django.","archived":false,"fork":false,"pushed_at":"2023-09-27T02:11:27.000Z","size":39,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-07T21:19:41.466Z","etag":null,"topics":["django","react","reactjs","vite"],"latest_commit_sha":null,"homepage":"","language":"Python","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/ChanMo.png","metadata":{"files":{"readme":"README.org","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,"governance":null}},"created_at":"2022-05-11T08:45:44.000Z","updated_at":"2024-12-05T13:51:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"b07b3e95-b281-47cd-acd6-f53caef70c69","html_url":"https://github.com/ChanMo/django-react","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/ChanMo%2Fdjango-react","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChanMo%2Fdjango-react/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChanMo%2Fdjango-react/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChanMo%2Fdjango-react/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChanMo","download_url":"https://codeload.github.com/ChanMo/django-react/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229669595,"owners_count":18104715,"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","react","reactjs","vite"],"created_at":"2024-12-14T06:14:28.161Z","updated_at":"2024-12-14T06:14:28.768Z","avatar_url":"https://github.com/ChanMo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"* Django + React\n\nAn easy way to use React with Django.\n\n\n** QuickStart\n*** Install\n#+BEGIN_SRC bash\n  pip install django-vite-react\n#+END_SRC\n\n*** Update Settings.py\n#+BEGIN_SRC python\n  INSTALLED_APPS = [\n      ...\n      'react',\n      ...\n  ]\n#+END_SRC\n\n*** Setup Vite\nCreate file package.json\n\n#+BEGIN_SRC json\n  {\n    \"name\": \"django-react\",\n    \"version\": \"1.0.0\",\n    \"description\": \"use react.js in django templates\",\n    \"main\": \"index.js\",\n    \"scripts\": {\n      \"dev\": \"vite\",\n      \"build\": \"vite build\",\n      \"test\": \"echo \\\"Error: no test specified\\\" \u0026\u0026 exit 1\"\n    },\n    \"keywords\": [],\n    \"author\": \"ChanMo\",\n    \"license\": \"ISC\",\n    \"devDependencies\": {\n      \"@vitejs/plugin-react\": \"^3.1.0\",\n      \"vite\": \"^4.1.1\"\n    },\n    \"dependencies\": {\n      \"react\": \"^18.2.0\",\n      \"react-dom\": \"^18.2.0\"      \n    }\n  }\n#+END_SRC\n\nCreate file vite.config.js\n\n#+BEGIN_SRC javascript\n  import { defineConfig } from 'vite'\n  import react from '@vitejs/plugin-react'\n\n  // https://vitejs.dev/config/\n  export default defineConfig({\n    plugins: [react()],\n    build: {\n      outDir: 'static/dist/',\n      manifest: true,\n      rollupOptions: {\n        input: [\n          'components/app.jsx',\n        ]\n      }\n    }\n  })\n#+END_SRC\n\nInstall npm package\n\n#+BEGIN_SRC bash\n  npm install\n  npm run dev\n#+END_SRC\n\n*** Create your jsx file\n\nExample =components/app.jsx=\n\n#+BEGIN_SRC javascript\n  import React from 'react';\n  import ReactDom from 'react-dom/client';\n\n  function App(props) {\n    return (\n      \u003ch1\u003e{props.title}\u003c/h1\u003e\n    )\n  }\n\n  const root = ReactDom.createRoot(document.getElementById(\"app\"));\n  root.render(\n    \u003cApp {...window.props} /\u003e\n  );\n#+END_SRC\n\n*** Use ReactMixin in your ClassView\n#+BEGIN_SRC python\n  from django.views.generic import TemplateView\n  from react.mixins import ReactMixin\n\n\n  class IndexView(ReactMixin, TemplateView):\n      app_root = 'components/app.jsx'\n      def get_props_data(self):\n          return {\n              'title': 'Hello'\n          }\n#+END_SRC\n\n*** Visit url in your brower\n\nhttp://localhost:8000/\n\n*** Build js\nBefore deploy, run =yarn dev=,\n\n\n** Deployment\n\nFirst of all, you need to compile the React files.\n#+BEGIN_SRC bash\n  npm run build\n#+END_SRC\nThis command will compile the React files into the ~static/dist~ directory.\n\nThen, make sure that ~DEBUG=False~ in the Django settings.\n\n** Final Structure\n\n#+BEGIN_SRC\n.\n├── backend\n│   ├── asgi.py\n│   ├── __init__.py\n│   ├── settings.py\n│   ├── urls.py\n│   └── wsgi.py\n├── db.sqlite3\n├── manage.py\n├── node_modules\n├── package.json\n├── todo\n│   ├── admin.py\n│   ├── apps.py\n│   ├── components\n│   │   └── todo.jsx\n│   ├── __init__.py\n│   ├── migrations\n│   │   └── __init__.py\n│   ├── models.py\n│   ├── tests.py\n│   ├── urls.py\n│   └── views.py\n├── static\n│   └── dist\n│       ├── assets\n│       │   └── todo-1cc3d04a.js\n│       └── manifest.json\n└── vite.config.js  \n#+END_SRC\n\n** Todo\n- [ ] easier to integrate\n- [ ] decorate function\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchanmo%2Fdjango-react","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchanmo%2Fdjango-react","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchanmo%2Fdjango-react/lists"}