Multiple django applications in one view

I think I have a simple question about the best organization of the code.

Let's say I have several applications that also implement how these applications should be presented at presentation level.

I'm trying to figure out how to organize the code if I need to present several applications on one page without using frames, of course?

A quick example: let's say I have two applications (app1 and app2) and their compatible model and views are implanted. Now I need my index page to contain a view of these two views. How can I implement a general view that still uses application views instead of directly accessing their models? I would prefer my application to still control its presentation.

thanks

+6
source share
2 answers

I think you can use the render_to_string shortcut. So in applications you add:

render_to_string(somestuff) # instead of render() or render_to_responce() 

and then in the index view something like this:

 render(request, 'index.html', {'block1': view1(request), 'block2': view2(request)}) 

PS: Also, after I wrote this, it doesn’t look very pretty (it looked better in my head :)).

+5
source

Great question, I will tell you how I did it.

I used (especially for the application) tags of custom templates. These template tags add extra material to the context that you can use in your templates. You can learn more about docs about custom template tags.

There's a good book, django Projects 2nd edition Practical Projects , which are a bit outdated, I think, but give you a great idea about the organization of the project,

+3
source

Source: https://habr.com/ru/post/901602/


All Articles