Problems in the use of django combined with ajax

clipboard.png
for example, in the template, I need to pass variables such as username,uid to the foreground to display user information, while data such as time,data needs to be updated in real time, so I use ajax to get the data in the frontend, but it is impossible to get the data in one function, so do I have to separate two functions to provide an interface for the frontend? Because this will lead to code duplication. (of course, I know that json, is the best way for ajax to get data. As an example, it must be irregular.)

Mar.06,2021

you can return different results in one function by determining whether the request method is ajax, but it is not recommended. It is recommended to return ajax. through another function

. It's not a problem for

code to repeat this, you can put the repeated code in another method and then reference that method.

Menu