templates - Django: How to integrate an app inside another app -


i know how can "call" application inside different application. basically, have, example :

  • a calendar app process render calendar in html
  • a "main" app shows index.html of website

i main app invoke calendar app , insert renders in sidebar.

the codeigniter framework example, can handle that. controller can invoke controller, saves returns (the html output) in variable, , includes variable in context used render final html file.

is possible django ? thanks

well, think may found solution. i'm new django don't know if it's way it, if brokes conventional rules, if open security hole, or if simply, there other better methods, anyway, works ...

so, created application calendar, , application show. want show invoke calendar, render template, , insert result inside template of show.

to used templateresponse instead of httpresponse on calendar side :

# calendar view  django.template.response import templateresponse  def render_calendar(request):     return templateresponse(request, 'calendar/calendar-template.html', {}) 

then on show side, templateresponse instance, invoke render() method, , insert rendered_content inside context :

# show view  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) 

and trick !


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -