Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't know any online examples showing just that, but I do have a personal project that includes that functionality; <a href="https://github.com/agconti/stamped" rel="nofollow">agconti:stamped</a>. </p> <p>The entire repo is linked above if you want to clone it and test it out, but the code pertinent to your needs would be;</p> <p>Ajax post:</p> <pre><code>var send_data = { 'name': place.name, 'address': address}; var csrftoken = $.cookie('csrftoken'); function csrfSafeMethod(method) { // these HTTP methods do not require CSRF protection return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); } $.ajaxSetup({ crossDomain: false, // obviates need for sameOrigin test beforeSend: function(xhr, settings) { if (!csrfSafeMethod(settings.type)) { xhr.setRequestHeader("X-CSRFToken", csrftoken); xhr.setRequestHeader("X-Requested-With","XMLHttpRequest"); } } }); $.ajax({ url: '/results/', type: 'POST', data: send_data, success: function(response, status, jqXHR) { $("#results").html(response); //console.log('success function resp'); //console.log(jqXHR.getAllResponseHeaders()); }, error: function(obj, status, err) { alert(err); console.log(err); } }); </code></pre> <p>An example of controlling for injecting a template and normal page viewing:</p> <pre><code>{% extends x|yesno:"stamped/blank.html,stamped/home.html" %} {% load stamped_custom_tags %} {% block results %} &lt;!-- Your HTML Here --&gt; &lt;h1&gt; title and stuff &lt;/h1&gt; &lt;div&gt; I contain things! &lt;/div&gt; {% endblock %} </code></pre> <p><code>home.html</code> is my <code>index.html</code> that contains the <code>#results</code> div!</p> <p><code>Blank.html</code>: </p> <pre><code>{% block results %}{% endblock %} &lt;!-- to allow for corrected shared rendering with ajax posts and normal django rendering --&gt; </code></pre> <p>Any normal django view that renders a page will return html that that ajax post above will inject into the <code>#results</code> div ( not included in the examples above ) on the page the ajax post initiated from. </p> <p>Edit from your comment:</p> <p>I'm assuming that what you really want to display in the preview is something important, like a title to an article. I would have a separate view for previews that renders a previews template. In that template I might do something like:</p> <pre><code>&lt;!-- blank because this will be injected into your page --&gt; {{ article_title|truncatechars:9 }} </code></pre> <p>You could then inject this into your page and display it on mouse over for example. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload