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,910 points
3,195 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.

Hope it helps!!

For more information about React, We highly recommend to join React JS Training online today.

Thank You!

answered Apr 30, 2019 by SDeb
• 13,300 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, 2020 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,560 points
1,443 views
0 votes
1 answer

How do I set custom HTML attributes in django forms?

Hello @kartik, You can change the widget on ...READ MORE

answered Jul 29, 2020 in Python by Niroj
• 82,840 points
2,937 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,460 points
1,595 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,560 points

edited Dec 18, 2018 by Nymeria 6,888 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,466 views
0 votes
1 answer
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,300 points
2,369 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,300 points
1,592 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP