Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
132 views
in Technique[技术] by (71.8m points)

reactjs - Make Calculations and Output result

I am creating an App using Django and React. I would like the user to input several numeric values on the Frontend and based on these values to perform some calculations and output the result in the Frontend (also store the values in the database).

I am confused on where on the backend I should add the logic to perform the calculations. On views.py or admin.py or on another file?

I am currently trying to create the logic on the admin.py file but I am not sure if this will allow me to make the result visible on the frontend.

question from:https://stackoverflow.com/questions/65648036/make-calculations-and-output-result

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

the calculation should be preformed in views.py and passed to the front end (for example by passing it as a dict )

result = number1 + number2    
content = {'result': result}
return render(request, 'app/file.html', context)

and then you can use it in a html file (that's an example you can pass the value elsewhere too) by using {{result}}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...