Code Monkey home page Code Monkey logo

django-reactify's Introduction

Django Reactify

Django Reactify is an app that allows developers to add and use React components in their Django app without using the legacy create-react-app.

Quick start

  1. Install the package via the following command:

    pip install django-reactify

  2. Add "reactify" to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'reactify',
    ]
    
  3. Run the following command:

    python manage.py reactify <app_name>

    Ensure that the templates directory exists in the specified app name.

    • Replace the app name with the existing Django app you want to reactify.

    • This command does the following:

      • Creates barbel and webpack configuration files in the app's root directory.
      • Creates package.json file with the scripts to run React development server.
      • Creates a react folder directory with the necessary files and subdirectories where you can add your react component files and redux actions and reducers.
      • Creates a react folder directory with the necessary files and subdirectories where you can add your react component files and redux actions and reducers.
      • Installs the basic npm development packages.
      • starts the react development server that listens on the changes made to the react components and compile a minimal js file that is rendered to the view.
  4. cd to the django app directory and run the following command:

    npm run dev

  5. Add the new view function to the views file to render the compiled version of the react app.

    def index(request):

    template_name = '<app_name>/index.html'

    return render(request, template_name)

  6. Add more React components to the react app's component folder.

Managing React Routes

If you don't configure Django urls to accept the Routes declared in the react, you will encouter 404 error.

To fix this, lets say you have react routes as follows:

<Switch>

<Route exact path="/" component={Main} />

<Route exact path="/login" component={LoginPage} />

<Route exact path="/services" component={ServicesPage} />

<Route exact path="/about" component={AboutPage} />

In the app urls file use re_path,

from django.urls import re_path

from .views import index

urlpatterns = [
re_path(r'', index, name="home"), ]

django-reactify's People

Contributors

bonifase avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jessmtermini

django-reactify's Issues

Error while reactify an existing django app (name="React_UI")

D:\professional\React\Reactify Django\website>python manage.py reactify React_UI
Traceback (most recent call last):
File "D:\professional\React\Reactify Django\website\manage.py", line 22, in
main()
File "D:\professional\React\Reactify Django\website\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\HP\Envs\Uliv\lib\site-packages\django\core\management_init_.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\HP\Envs\Uliv\lib\site-packages\django\core\management_init_.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\HP\Envs\Uliv\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\HP\Envs\Uliv\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "C:\Users\HP\Envs\Uliv\lib\site-packages\reactify\management\commands\reactify.py", line 14, in handle
subprocess.run(f'''
File "c:\users\hp\appdata\local\programs\python\python39\lib\subprocess.py", line 505, in run
with Popen(*popenargs, **kwargs) as process:
File "c:\users\hp\appdata\local\programs\python\python39\lib\subprocess.py", line 951, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "c:\users\hp\appdata\local\programs\python\python39\lib\subprocess.py", line 1420, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 3] The system cannot find the path specified

Facing above issue while run above command.
What is the issue? I need help.

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.