Hola todos he pensado guardar en una variable en javascript un dato y luego enviarlo a una vista de django para usar ese dato, en este caso la variable formatSelected, aclaro q el codigo de javascript está en un template de django, O que opciones tengo para lograrlo?
Script de javascript
<script>
$(document).ready(function() {
$(".formato-button").on("click", function() {
const formatSelected = $(this).parent().parent().parent().find(".formato-title").text();
let height = 0;
let width = 0;
if (formatSelected == "A4") {
width = 2480;
height = 3508;
} else if (formatSelected == "Facebook") {
width = 1200;
height = 630;
} else if (formatSelected == "Instagram") {
width = 1080;
height = 1080;
}
localStorage.setItem("width", width);
localStorage.setItem("height", height);
})
});
vista django
class FondoView(LoginRequiredMixin, TemplateView):
template_name = 'fondo.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
all_records = Image.objects.filter(format="variable javascript")
filtered_records = None
filter_category = int(self.request.GET.get('search_tipo')) if self.request.GET.get('search_tipo') else 1
filter_name = self.request.GET.get('search_fondo')
if (not filter_category and not filter_name):
image_json = serializers.serialize('json', all_records)