Django: how to integrate an application into another application

I would like to know how we can “call” an application from another application. Basically, I have, for example:

  • a calendar application that performs a specific process for displaying a calendar in html
  • The "main" application that displays the website index.html

I would like the Main application to call the Calendar application and insert what it displays in the sidebar.

For example, a CodeIgniter framework can handle this. The controller can call another controller, save what it returns (html output) in a variable, and finally include this variable in the context that will be used to render the final html file.

Is this possible with Django? Thanks

+5
source share
2 answers

Well, I think I can find a solution. I'm new to Django, so I don’t know if this can be a good way if it breaks some normal rules, if it opens some kind of security hole, or, if just, there are other best methods, but it works anyway ...

So, I created the Calendar application , and my Show application . I want to Show in order to call up the Calendar , display its template and insert the result inside the Show template .

For this, I used TemplateResponseinstead HttpResponseof the calendar side:

# Calendar view

from django.template.response import TemplateResponse

def render_calendar(request):
    return TemplateResponse(request, 'calendar/calendar-template.html', {})

"" TemplateResponse, render() , , rendered_content :

# Show view

from calendar import views

def show(request, show_id):
    cal = views.render_calendar(request)
    cal.render()
    context = {"calendar": cal.rendered_content}
    return render_to_response("show/show-template.html", context)

!

+4

...

{% ssi%}, , , .

0

All Articles