django-templates

Django - download file from FileField()

女生的网名这么多〃 提交于 2020-12-06 16:52:25
问题 I'm struggling with the following problem. I have a database model with FileField() . models.py class InputSignal(models.Model): input_file = models.FileField(upload_to='signals/', null=False, ) A view that displays records from this table. It also supports deleting specific rows. views.py def storage_list(request): signals = InputSignal.objects.filter(author=request.user) if request.method == 'DELETE': id = json.loads(request.body)['id'] signal = get_object_or_404(InputSignal, id=id) signal

Is there a way to pass a variable to an 'extended' template in Django?

别来无恙 提交于 2020-11-30 08:22:05
问题 I want to add some flexibility to my layout template, but I can't find any way to do so. I'm looking for a way to extend my layout template with variable, i.e. to pass a variable up in the template tree, not down. # views.py def my_view_func(request): return render(request, "child.html") # child.html {% extends 'layout.html' with show_sidebar=True sidebar_width_class="width_4" %} <div>Templates stuff here</div> # layout.html {% if show_sidebar %} <div class="{{ sidebar_width_class }}"> {%

Is there a way to pass a variable to an 'extended' template in Django?

寵の児 提交于 2020-11-30 08:11:51
问题 I want to add some flexibility to my layout template, but I can't find any way to do so. I'm looking for a way to extend my layout template with variable, i.e. to pass a variable up in the template tree, not down. # views.py def my_view_func(request): return render(request, "child.html") # child.html {% extends 'layout.html' with show_sidebar=True sidebar_width_class="width_4" %} <div>Templates stuff here</div> # layout.html {% if show_sidebar %} <div class="{{ sidebar_width_class }}"> {%

Is there a way to pass a variable to an 'extended' template in Django?

别等时光非礼了梦想. 提交于 2020-11-30 08:11:44
问题 I want to add some flexibility to my layout template, but I can't find any way to do so. I'm looking for a way to extend my layout template with variable, i.e. to pass a variable up in the template tree, not down. # views.py def my_view_func(request): return render(request, "child.html") # child.html {% extends 'layout.html' with show_sidebar=True sidebar_width_class="width_4" %} <div>Templates stuff here</div> # layout.html {% if show_sidebar %} <div class="{{ sidebar_width_class }}"> {%