React.js with Django without using webpack

I would like to start using React components in a Django project. React will be used only for some parts of the project (for example, some filters, search field, etc.).

I was looking for the answer in another similar question , but this does not work for me, because I do not want to use python-webpackespacially and js-hosthow it will start an additional process and it is difficult to configure and deploy it.

Does anyone know any other good solution how to use React with Django?

+4
source share
2 answers

Django Compressor JSX ( pull request), .

:

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react.js" type="text/javascript" />

{% compress js %}
<script src="{% static 'components/react_component.jsx' %}" type="text/jsx", charset="utf-8" />
{% endcompress %}

<div id="my-component"></div>

react_component.jsx:

React.render(
   <Some_Component />,
   document.getElementById('my-component')
);

, json . ReactComponent, .

var Some_Component = React.createClass({
  getInitialState: function() {
    return {
      items: [],
      loaded: false
    }
  },

  componentDidMount: function() {
    $.get('/my_json', function(result) {
      if (this.isMounted()) {
        this.setState({
          items: result.items,
          loaded: true
        })
      }
    }.bind(this))
  },
  ...
});
0

, http://www.noobmovies.com, Django, Django-Rest-Framework ReactJS. , 2 , YouTube.

1: https://www.youtube.com/watch?v=wU-KUapq1kQ

2: https://www.youtube.com/watch?v=6tiaiSr6Pqw

Django, , , . API REST AJAX React JSON . api React.

+6

All Articles