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, 2019 in Python by ana1504.k
• 7,890 points
543 views

2 answers 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, 2019 by SDeb
• 13,250 points
0 votes
Did you ever find a solution for this? It seems to me it is a very valid use case, but I cant find any lib out there that helps with this. Maybe this is a space for a new open source lib.
answered Feb 6 by martin

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,540 points
113 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 aryya
• 7,370 points
340 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,540 points

edited Dec 18, 2018 by Nymeria 2,327 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,540 points
282 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, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,054 views
0 votes
0 answers
0 votes
1 answer

How to generate urls in django?

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

answered Apr 12, 2019 in Python by SDeb
• 13,250 points
75 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, 2019 in Python by SDeb
• 13,250 points
119 views