How to render a Django Serializer Template with React Js? - javascript

I've set up my api for a basic model in my Django project. I've defined my post and get methods and everything is working correctly. Now, I'm wondering how I can render my Django model using react js. Essentially, I'm wondering how I can use react js to assign my django model values that were inserted using reactjs instead of django. For example, if my django model's fields are "name" and "id", how can I assign these fields using reactjs instead of the basic Django page(I've inserted my current page below)? Do we need to use axios or jquery to make these transitions? Thanks.

Instead of thinking how to render your django model in react, i think it is easier to understand when you think in the server-client model.
Basically you want to get you data from your django server and then show it in the client, using react.
To do this with Django rest framework, the best way is to make HTTP requests from the client to the server. You could use the browser built-in fetch api from javascript or a http library like axios.
You can read more about fetch here

Related

Live database fetch using Laravel and React

I'm new to React and still learning Laravel, and I was wondering how can I live fetch data from the database using the Laravel Controllers. I want to use React too but I really don't see his utility there.
From my searches, I found an Ajax method, but I really want to use just Laravel and React to do so. Is it possible?
Like displaying the new users directly from the database without refreshing the whole page? I'm using Mysql to manage my database.
First of all, You need to set up laravel sanctum to get the authenticated data.
But if you don't want the authenticated data. You can just use a fetching library like axios to fetch data from the laravel. You need to add the cors (which is localhost:3000) in app.cors.php file of laravel root directory.
But if you are using reacjs with laravel like with intertia.js (which I prefere btw), You don't need the cors, laravel will work out of the box....

Generate equivalent HTML generated by Javascript (VueJS) on backend

I am asking this because I don't know if it's possible and don't know the terms to label this.
I have a VueJS crud app that grabs data from an API backend, and then renders it in great HTML. Thanks JavaScript, and V8 since I use Chrome.
Now, I'd like to send someone an HTML email with a snippet of the table embedded. That is a backend process. But I obviously don't want to rewrite the VueJS HTML on the backend or in another place.
Is there any way, from the backend only, to call the VueJS coding and grab the HTML, or an innerHTML section, as if I'd called it on the front end?
The answer to this is to use NodeJS and perform Server Side Rendering
This will require using the render method in VueJS which is different than what my CRUD application is written in.
Also as discussed in the link above, reactivity doesn't exist on the server side.
And in addition, the actual data that would be listed in a table needs to be pre-fetched.

Vue.js as ExpressJS view engine

I am looking for something like React for ExpressJS but working with Vue.js.
I have problem with passing data from database (mongoose) to view. As for now, I am using handlebars view engine to pass data with mustache to script tag and then passing them to vue files through window object, but I don't think it's a best way to do it.
Have somebody used vue.js , express.js and mongoose for SPA applications?
I don't believe that there is anything to use Vue.js with the Express view engine API. Nevertheless, Vue 2.0 (Release Candidate) supports server rendering.
https://www.npmjs.com/package/vue-server-renderer
The following link has an example using Express.
https://github.com/vuejs/vue/blob/next/packages/vue-server-renderer/README.md

Pass a request to a DJANGO REST api using Angular and then return those results in a DJANGO view

Ok, so basically what is happening is I have a search input on my index page. The user types something in the search input, and that is sent to the Django REST api which returns the data in JSON format. I can loop through that results array using Angular ng-repeat. But my question is: is there a way to send that request to another django view and have django return the values using a for loop and a template that I already created?
( I am trying to avoid recreating the template specifically for Angular because that would be repetitive)
Any suggestions, or help on this comes much appreciated. Thank you in advance for taking the time to help me.
All the best.
It depends on the architecture of your application.
If you are building your client as a single page web application using Angular & your business logic is served using the Django REST API in JSON/XML format. Then rendering of the view should be the responsibility of the client side code.
As per me whatever you are doing looks perfectly okay. I don't see any redundancy of the templates in this architecture.

Django angular database integration

I have a django project that uses postgresql. I am trying to use angular as a front end in my html pages. Which is the best approach to use the angular js controllers in the django project to connect to the django models and the database to perform basic operations like insert, delete, update etc?
Currently i just have static data that i defined in my angular controller. But i would like to know how to get the data from the database dynamically. Any advice will be helpful
As per my experience with Django and AngularJs, first you should make api in django to get the data from database. Afterthat, in single page application, you should make angularjs service for each api in controller. After rendering data, you can submit / modify your data either through api or through form submission(with form validation).

Categories

Resources