$ cd
$ mkdir React
$ cd React
$ django-admin startproject Config
$ mv Config backend$ cd backend
$ python -m venv .venv
$ ln -sf ./.venv/lib/python3.11/site-packages django
$ source ./.venv/bin/activate$ pip install --upgrade pip setuptools wheel
$ pip install django djangorestframework yfinance ta django-cors-headers pandas
$ python manage.py startapp api
【postgres】
$ sudo dnf install python3.11-psycopg2 python3.11-devel
$ pip install psycopg2
$ cd
$ cd React
$ npx create-react-app frontend
$ cd frontend
$ npm install axios chart.js react-chartjs-2
【起動】
$ cd backend
$ ./manage.py runserver
$ cd frontend
$ npm start
【httpd に組み込み】
$ npm run build
【typescriptアプリ】-- 純粋な React アプリ
$ npx create-react-app frontend_ts --template typescript
【next.js typescriptアプリ】Next.js の App Router構成 を使ったプロジェクト
$ npx create-next-app@latest frontend_nx --app --typescript --tailwind --eslint --src-dir --import-alias "@/*"
my-next-app/
├─ app/
│ ├─ page.tsx ← ルートページ(App Router形式)
├─ public/
├─ styles/
│ └─ globals.css
├─ tailwind.config.ts
├─ postcss.config.js
├─ tsconfig.json
├─ next.config.js
├─ package.json
npm install next-auth chart.js react-chartjs-2 axios
【起動】
cd my-next-app
npm run dev
【3つのタイプ】
(1) frontend : CRA (create-react-app)
(2) frontend: React + TypeScript(CRA + TS)
(3) Next.js(App Router / SSR 対応)
【まとめ表】
構成 方法 本番ビルド Apache連携
Django mod_wsgi or Gunicorn+Proxy collectstatic WSGIScriptAlias 使用
React (CRA) 静的ビルド (build/) npm run build DocumentRoot に設置
Next.js(静的)next export npm run build && export /out を配信
Next.js(SSR) Node.jsサーバー+mod_proxy npm run build Apacheから3000番へProxy
【Django 側】
(1) Config/settings.py
(2) Config/urls.py
(3) api/views.py
(4) api/urls.py
(5) api/serializers.py
(6) templates/index.html
【REACT CRA】
(1) package.json に追記( "proxy": "http://localhost:8000")
(2) rm App.js; cp App.jsx
0 件のコメント:
コメントを投稿