2

i am new to react , i am building simple blog where user can post with title and body

in html its done with listview with:

{% for x in object_list %}
{% endfor %}

but in react component its not getting good result and showing error

here is my code:

models

class post(models.Model):
    title = models.CharField(max_length=100)
    body=models.TextField()

views

class list(ListView):
    model = post
    template_name = 'index.html'

post.js

function Post(){
return(
    {% for x in object_list %}
    {% endfor %}
)

}

in react what can i do to retreive data from model like we used to do in normal html, or show the object from model in components??

  • You cant display data in react component in the similar way as in django template. You must fetch data from django with some REST API. Here you have good tutorial https://saasitive.com/django-react/boilerplate/ (production ready) – pplonski Mar 06 '21 at 19:13

0 Answers0