Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

reloading a django view function withouit resetting context data

//parent_template.html
{% load static %}
<script src="{% static "jquery.js" %}"></script>

{% block first %}
<div class="row">
    {% for x in my_list %}
    <button class="some-filter" id="{{x}}"></button>
    {% endfor %}
</div>
{% endblock first %}

{% block second %}
<div class="row" id="some_id"></div>
{% endblock second %}

<script>
     $(".some-filter").on({
       click: e=> {
           var name = $( e.target )[0].id;
           $.ajax({
             url: '/ajax/info_getter/',
             data: {
               'name': name,
             },
             dataType: 'html',
             success: function (data) {
               if (data) {
                 $("#some_id").html(data);
                 $(".some-filter").removeClass('selected');
                 $( e.target ).addClass('selected');
               }
             }
           });
       }
   })
</script>



// child_template.html
// my big ass template containing lots of image files
{% load static %}
...other stuff

// urls.py
from django.urls import path
from . import views
urlpatterns = [
    ...
    path('ajax/info_getter/', views.info_getter, name='info_getter'),
    ...
]



// views.py
from django.shortcuts import render
...
def info_getter(request):
    name = request.GET.get('name', None)
    if name:
        context["name"] = name

    response = render(request, "child_template.html", context=context)
    return response
Comment

PREVIOUS NEXT
Code Example
Python :: rom requests_html import HTML 
Python :: dataframe to DatasetDict 
Python :: function for permutation sampling and test statistic from a specified operation 
Python :: django filter form view 
Python :: python regex compile 
Python :: different accuracy score for knn 
Python :: time for range in python 
Python :: python 2 factor authentication 
Python :: how to rub softwares using python 
Python :: threshold image segmentation code python 
Python :: python split get array for loop 
Python :: Extract columns of dataframe to make new dataframe 
Python :: looping through the dict. and return the key with the highest value 
Python :: django null first 
Python :: Understand the most appropriate graph to use for your dataset 
Python :: change dimension position of numpy array 
Python :: biopython parse fasta 
Python :: Mapping using dictionary 
Python :: how to change graph after every second in python 
Python :: django Account has no customer 
Python :: how to drag a box on your screen python 
Python :: python 5 minimal values from array 
Python :: how to import qpalette pyqt5 
Python :: ValueError: expected sparse matrix with integer values, found float values 
Python :: expionenttiation python 
Python :: decleration of array in python 
Python :: Empty a variable without destroying it 
Python :: add up all the numbers in each row and output that number output the grand total of all rows 
Python :: geopy set proxy 
Python :: access data frame element by loc 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =