Django forms in ReactJs

0 votes
Is there any way I can use Django forms inside a ReactJS script, like include {{ form }} in the JSX file?

I have a view which displays a form and it is rendered using React. When I load this page from one page the data in these fields should be empty, but when I hit this view from another page I want the date to be prefilled in this form. I know how to do this using Django forms and form views, but I am clueless where to bring in React.
Apr 30 in Python by ana1504.k
• 7,870 points
51 views

1 answer to this question.

0 votes
The {{ form }} statement is relative to Django template. Django templates responsible for rendering HTML and so do React, so you don't have to mix the two together.

What you probably want to do is to use the django form validation mechanism server side, et let React render the form client side. In your django view, simply return a json object that you can use in your React code to initialize your form component.
answered Apr 30 by SDeb
• 13,180 points

Related Questions In Python

0 votes
1 answer

How should I write tests for Forms in Django with Python?

from django.tests import TestCase class MyTests(TestCase): ...READ MORE

answered Nov 20, 2018 in Python by Nymeria
• 3,520 points
41 views
0 votes
1 answer

How to switch pages using Ajax in Django?

You should use django-pjax which is built exactly for ...READ MORE

answered Oct 9, 2018 in Python by ariaholic
• 7,340 points
180 views
0 votes
1 answer

How to get all related Django model objects in Python?

This actually gives you the property names ...READ MORE

answered Nov 14, 2018 in Python by Nymeria
• 3,520 points

edited Dec 18, 2018 by Nymeria 758 views
0 votes
1 answer

How to run django unit-tests on production database in Python?

In case someone googles here searching for ...READ MORE

answered Nov 28, 2018 in Python by Nymeria
• 3,520 points
75 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 328 views
0 votes
1 answer

How to generate urls in django?

If you need to use something similar ...READ MORE

answered Apr 12 in Python by SDeb
• 13,180 points
38 views
0 votes
1 answer

Django session doesn't work in Firefox

You can try this: request.session.modified = True I hope ...READ MORE

answered May 6 in Python by SDeb
• 13,180 points
37 views