Git Product home page Git Product logo

djcra's Introduction

djcra

Django โค๏ธ create-react-app integration example

how to run project

In frontend development mode:

  • set FRONTEND_DEV = True in settings.py
  • run servers
$ REACT_APP_PUBLIC_URL=http://localhost:3000 npm start
$ python manage.py runserver
  • open http://localhost:8000

In backend-only development mode:

  • set FRONTEND_DEV = False in settings.py
  • build static files
  • run python server
$ npm run build
$ python manage.py runserver
  • open http://localhost:8000

In production mode

  • set FRONTEND_DEV = False in settings.py
  • build static files
  • collect static files
$ npm run build
$ python manage.py collectstatic

In production with cdn

  • update STATIC_URL and FRONTEND_DEV in settings.py file.
STATIC_URL = 'http://cdn.mysite.com/static/'
FRONTEND_DEV = False
  • build static file
REACT_APP_PUBLIC_URL=http://cdn.mysite.com npm run build

you can see cdn branch of this repo for more detail.

the ๐Ÿ’” parts

problems that need your help.

I hope I see solution in next CRA version with running

PUBLIC_URL=http://localhost:3000 npm run start

hot reload problem

http://localhost:8000/sockjs-node/ not found in django.

images problem

CRA assets starts with /static/. so we need add http://localhost:3000 before them.

import logo from './logo.svg';
console.log(logo); // "/static/media/logo.5d5d9eef.svg"
<img src={(process.env.REACT_APP_PUBLIC_URL || '') + logo} alt="logo" />

what happen until now

create react app named cra-prj

$ create-react-app cra-prj

create django project named djcra

$ django-admin startproject djcra
$ mv djcra django_prj
echo 'Django==1.10.5' > django_prj/requirements.txt

I add some files to projects

djcra's People

Contributors

smmoosavi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

zubairalam

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.