Questions tagged [django-templates]

1

votes
1

answer
41

Views

Overriding a template in Django

I'm using this library to add a sessions tab on my django project. I'm calling the module's template from my project using this line: Sessions It works, but now I'd like to style the page, and to do that I need to override the module's template with my own template. So, as the module says here, I in...
Jack022
1

votes
1

answer
39

Views

Why my ajax function are not working on infinite scrolling?

I am building a webpage having infinite scroll using waypoints.js with backend as Django.The problem is, my jquery and ajax functions are not working on newly generated content while they are working with content on first page. **EDIT:-**I am updating my code so that it will be easier to undertsand...
Gagan
0

votes
0

answer
6

Views

Django: create an admin section gathering info from multiple models

I've been asked to add in the admin site of a Django project a new section that will gather information from several models (as it were a Database view) but I'm not allowed to change or add tables/views in the db. Checking similar questions custom page for Django admin in SO, I've ended up trying to...
Manu
0

votes
0

answer
3

Views

Django: database filter output displays <QuerySet [<model: model object (value)>]>

I am new to django, i am trying to import the data from a database by using multiple filters. views.py from django.shortcuts import render from django.http import HttpResponse from .models import NodesdataArchive # Create your views here. def home_view(request, *args, **kwargs): data = Nodesdata...
selvam samymuthu
0

votes
0

answer
21

Views

Reduce number of queries made to render list of items with same in-line editable field

While rendering a table of items, if the value for field X is not defined, it is rendered as a select element. Django makes a query for each select element and these can add up and cause delays in large tables. What is the best way to reduce the number of queries? views.py from rest_framework impor...
silverstripes
1

votes
1

answer
445

Views

'CsrfViewMiddleware' object is not iterable

I am new to Django, and I just took over from another developer on this project. All I have done so far is clone the code from git and install the dependencies. Immediately after setting up the project, and running python manager.py runserver and going to localhost:8000/admin I get an error stating...
0

votes
0

answer
3

Views

django-hitcount - display the date and ip of each recorded “hit”

This is a noob question, so excuse the lack of understanding. I'm using python 3.6 & django 1.10.5. I've been given a test page that now uses django-hitcount to track the number of times a document is 'hit' - viewed and downloaded. This seems to be working OK. I now want to extend the code so that I...
user3354539
1

votes
1

answer
288

Views

Equivalent of using if .. else as an expression in the Django Template Language

In Python, there are two ways to use if and else: either for Boolean flow control, in which case it is used with colons and indentation, or as an expression on a single line as described in https://www.pythoncentral.io/one-line-if-statement-in-python-ternary-conditional-operator/. As far as I can t...
Kurt Peek
1

votes
2

answer
681

Views

Django: List Products of each Categories in a page

I have a few categories and I would like to list the products per category in the format below (categories is an FK to products): Category 1 bunch of products .... Category N bunch of products I have tried many ways but so far I only get the categories but not the products to show in my HTML. model...
Inconnu
1

votes
2

answer
32

Views

Django Query: How to find all posts from people you follow

I'm currently building a website with the Django Framework. I want on the homepage of my website to display all posts made by people the user is following. Here are the classes for Profile, Story and Follow: class Profile(AbstractBaseUser, PermissionsMixin): email = models.EmailField(unique=True) fi...
Frederik Vanclooster
1

votes
1

answer
58

Views

How can I get the current user's group in forms.py in Django?

I have a scenario where i need to pass the logged-in user's groud name and get the list users in that group. forms.py -- in the below code i need to pass the user's group instead of Banglore class UpateTaskMaster(forms.ModelForm): def __init__(self, *args, **kwargs): super(UpateTaskMaster, self).__i...
Mohamed Naveen
1

votes
1

answer
279

Views

DJango-tables2 how do I refresh/update the table on the webpage without hitting refresh button

I followed the DJango-tables2 official tutorial and was able to create data set in the terminal using: Person.objects.bulk_create([Person(name='Jieter'), Person(name='Bradley')]) However, the new data in the table on the website doesn't show up until I hit the refresh button. My question is how the...
szd116
1

votes
2

answer
101

Views

Django Model serving Media Files

I have two models: Packages and Images. Images has many to one relation with Packages. Images table has a foreign key package_id. I have to display the attributes country, price of Packages with one image related to the package. There can be many images related to a single package however, I have to...
Shekhar Khatri
1

votes
0

answer
87

Views

How to use formatvalue filter for field in form template?

In Django templates, we use the filter on value fields such as {{value | formatvalue}} I want to generate my form dynamically like the example below. {% for field in form %} {{ field }} {% endfor %} As you know, the field attribute will be generated as an html element. Is there a way to add a filter...
Harun ERGUL
1

votes
0

answer
49

Views

How to re-increment each id attribute in Formset after deleting a Form in Django?

I currently have a formset rendered to a template, where I do a for loop over it to display each form. I have a button which adds extra forms and I also have a delete button which removes any of the forms. My problem is when I delete one of the middle forms, the incrementing from the formset managem...
David Arce
1

votes
1

answer
27

Views

Widget attribute does not work

I have two forms and a formset. I have given __init__ for both the forms. However in my template only my POBodyForm is rendered with the attributes. Looks like __init__ of POHeaderForm is not working. I am not sure what is the error. Can someone please advise? I have been using the similar __init__...
Thaha
1

votes
1

answer
157

Views

Django Multiple Record Insert CreateView ( not enough values to unpack (expected 2, got 1))

i am getting the following message while saving the record. not enough values to unpack (expected 2, got 1) I am getting a Acquisition ID and attaching qoutations(single or multiple ) and once saving the record the system pops out the error. there is no error if i select the ACQID from createview...
Najeebullah Usmani
1

votes
0

answer
47

Views

django create N number of forms in template

I was wondering if it was possible to write a more generic form to use as a template so that during the render it will create as many forms as necessary? If not how would one write code to create N number of forms, where the number is Dependant on the result of some query set, and also the options i...
noone392
1

votes
1

answer
329

Views

Implementing themes in Django (Custom templates by users)

I want to implement the feature for admins to set custom templates. Like they can place themes or templates in a particular folder relative to the home folder. Each theme may have a folder and some config or preview for example(optional). 1) First I need to figure out how to set custom templates di...
Kotlinboy
1

votes
0

answer
250

Views

My HTML table is with pagination, and I want to download the whole table rather than the current visiable rows

Am new to exporting html table to csv. The code below could export only the current visible page, but I want to be able to download from pages 1 -- 200 for instance at a click of a button. // download html table to csv file function downloadCSV(csv, filename) { var csvFile; var downloadLink; csvFile...
Danny76
1

votes
0

answer
236

Views

How to Upload a text file in django using templateview based view and model based forms

I am new to django and stuck on uploading a simple file. I am using TemplateView as views and model based form. I am stuck here. I have no idea what to do. I am using django 2.0. I have attached the code what I have done so far. setting.py import os BASE_DIR = os.path.dirname(os.path.dirname(os.path...
Arshad
1

votes
0

answer
192

Views

How to determine wagtail Page content type within django template?

The core problem is that handling of wagtail RichTextField and StreamField is radically different in the templates. I'm trying to accomplish something similar to the following: {% with post=post.specific %} {% if post.content_type == 'streamfield' %} {% include_block post.body %} {% else %} {{ post....
NarūnasK
1

votes
1

answer
91

Views

Copy ManyToMany Value

I am currently trying to copy a many-to-many-field from one model to another but running into a bit of trouble. I have been able to create the model fine with a many-to-many-field with a ModelMultipleChoiceField, and the model saves the way I want it to. When I try to copy it to another model, I d...
Steve Smith
1

votes
0

answer
26

Views

How do I display only the non empty or non null fields from a django a model?

I have a model called Address and it has about 7 different fields. The corresponding form for this model is completely optional and the user may fill in either all 7 fields or just 1 field or none of the fields. There are no required fields here. Now, if the user has filled only the city and countr...
DeA
1

votes
2

answer
118

Views

Static language to render images in loop - Upload through Django admin

I uploaded images with admin, but cannot render them in the template. What am I missing? Settings.py STATIC_URL = '/static/' STATIC_DIRS = { os.path.join(BASE_DIR, 'static'), } MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') Models.py class Function(models.Model): name = models.Ch...
1

votes
0

answer
36

Views

Many To Many Field Multiple Users

I'm slowly gaining my knowledge with Django, but this one has me stumped. I am trying to create a form that multiple users need to approve. In doing this, I have created a CreateView with a modelform and that works fine. I have also created an UpdateView, and this works fine as well, with the cav...
Steve Smith
1

votes
1

answer
599

Views

Using Django to create sessions and buttons connecting Products to a shopping cart through templates and views.py

Sorry for the length (Thought the info was relevant), and thank you for helping understand how this works. I'm trying to use sessions and Django templates to add items to shopping cart. I'm fairly new to learning Django and have painstakingly read through a bunch of documentation and Stack Overflow...
juju
1

votes
1

answer
33

Views

Get_absolute_url with ForeignKey doesn't work in Django template

I'm trying to return JsonResponse in Django View: return JsonResponse(render_to_string( 'notifications/notifications_dropdown.html', {'new_notifications': new_notifications}), safe=False) notifications_dropdown.html: {% if new_notifications %} {% for notification in new_notifications %} {{ notificat...
12bogdan03
1

votes
2

answer
44

Views

How to add category to my polls app?

My models.py is class Question(models.Model): question_text = models.CharField(max_length= 100) pub_date = models.DateTimeField('Date Is Published') image = models.ImageField(upload_to='Question_Image', blank=True) def __str__(self): return self.question_text And, I have to add a class 'category' so...
arpan mahatra
1

votes
1

answer
24

Views

How do I display the views output on my template in tabular rows?

I am using Django as my web framework. I have written a views function like this.. to fetch a list of all items under the keys UserId and AccountNum from an AWS DynamoDb table : def dsctbl2(request): dynamodb=boto3.client('dynamodb', region_name='us-west-2') response = dynamodb.scan( TableName='User...
Siddharth Singh
1

votes
1

answer
147

Views

Numerical operation with absulute value in Django

I tried to add three different absolute value in my template but I got always 0. I try to explain it: My values: a=-7 b=8 c=10 I tried this method with Django mathfilter: {{a|abs|add:b|abs|add:c|abs}} I always got 0 because I think the mathfilter can't handle many abs value. Could anyone give me an...
1

votes
0

answer
65

Views

How to print in template something when queryset build with union() changes?

I have two queryset: q1 and q2. I make a union of them with q1.union(q2) Now, when I print in template the queryset with a for loop, how can I print something between the two querysets? Something like: Featured results (q1 forloop) Other results (q2 forloop) Why I thought to use union instead of sep...
user1518217
1

votes
1

answer
72

Views

How to make Python property object human-readable - Rendering it through Django templates

I have this property that should display the total price for each product, and I call it in my views and render it. On the rendered page, it just shows up as How am I supposed to make this human-readable? I know this is really simple, and I can't figure out how. I tried the following within my cart...
juju
1

votes
1

answer
54

Views

how can we query foreign key and get results of objects which are connected to foreign key

How can I can use managers to query my foreign key and then retrieve objects that are connected to foreign key? Here is my models.py: from django.db import models # Create your models here. class BookManager(models.Manager): def title_count(self,keyword): return self.filter(title__icontains=keyword)...
1

votes
0

answer
23

Views

app doesn't work with otree 1.4.4

I have an otree app that works perfectly on my computer, with otree 1.3.1. In this app, I specify several settings variables. One of those is called 'sure', which can take values 0 or 1, and I refer to it in models.py and views.py as self.settings.config['sure']. In my html page, I have several con...
arsik87
1

votes
1

answer
35

Views

dictionary values can't be iterated through using their corresponding keys in django template [duplicate]

This question already has an answer here: Django template how to look up a dictionary value with a variable 6 answers So I have a nested dictionary in the form of the following: data = { server:{'rating':{'class':'good, 'desc':'whatever'}, 'vulnerabilities':{'heartbleed':{'severity':'critical', 'd...
Miind
1

votes
0

answer
49

Views

BooleanField not showing the selected value on Update

In a model I have defined the following field: manager = models.BooleanField(choices=BOOL_TYPE_CHOICES, default=BOOL_TYPE_NO) forms: 'manager': RadioSelectWidget(choices=BOOL_TYPE_CHOICES) const BOOL_TYPE_NO = 0 BOOL_TYPE_YES = 1 BOOL_TYPE_CHOICES = ( (BOOL_TYPE_NO, 'No'), (BOOL_TYPE_YES, 'Yes') ) w...
user3541631
1

votes
0

answer
21

Views

how to handle new button in submit_line.html in django

i already create a class to validating xml file, and i try in actions its work but how i can make the script work in new button i create in submit_line.html this is my admin.py with actions class CrsFileAdmin(admin.ModelAdmin): list_display = ('fi', 'file', 'import_datetime', 'state') readonly_field...
putra
1

votes
1

answer
170

Views

How to compare float variable in django template?

Attendances is a list of float variables. Even when the value is less than 75, the first case is executed. I know that by default the django template see's a variable as a string. I know how to convert the variable to integer by making it {% attendance|add:0 %}, but what do I do when the values are...
Aasif Faizal
1

votes
1

answer
332

Views

Invalid block tag on line 3: 'else'. Did you forget to register or load this tag?

I have my main home template, that I would like to extend one of two sets of headers from but I am getting an error that seems to indicate the else does not work in this statement. I also tried changing to an elif for when user is not logged in and the elif was shown as undefined. These are the firs...
Skyler

View additional questions