Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django render template in a pop-up

As a beginer with javascript, I am looking for a manner to render a template from django in a javascript popup. Thanks.

like image 213
ScotchAndSoda Avatar asked Jan 30 '12 12:01

ScotchAndSoda


People also ask

How do I create a pop up message in Django?

To display alert messages in Django, (1) check that the settings are configured properly, (2) add a message to a view function, and (3) display the message in a template. INSTALLED_APPS = [ ... 'django. contrib. messages', ... ]

How do I add a template to Django?

To configure the Django template system, go to the settings.py file and update the DIRS to the path of the templates folder. Generally, the templates folder is created and kept in the sample directory where manage.py lives. This templates folder contains all the templates you will create in different Django Apps.

What is the Render () function in Django?

In Django, render() is one of the most used functions that combines a template with a context dictionary and returns an HttpResponse object with the rendered text.

What is render to string in Django?

render_to_string is a callable within the django. template. loader module of the Django project. get_template and select_template are a couple of other callables within the django. template.


1 Answers

create view and django template and in django template create link to new page

<script language="javascript" type="text/javascript">
<!--
function popitup(url) {
    newwindow=window.open(url,'{{title}}','height=200,width=150');
    if (window.focus) {newwindow.focus()}
    return false;
}

// -->
</script>

<a href="popupex.html" onclick="return popitup('/example/popup')"
    >{% trans 'Link to popup' %}</a>

so you must have another app with '/example/popup' url

ps: there are many other way ... its only one suggestion!

like image 50
Mohammad Efazati Avatar answered Sep 18 '22 22:09

Mohammad Efazati