in Education by
I am a beginner at Django and I am attempting to create a custom table using a html template called law.html. Within law.html I have the following code. {% for name in all_data.Solicitor_Name %} {% endfor %} {% for office in all_data.Office %} {% endfor %} The output produces the desired table headings perfectly. Also, the Solicitor_Name column is filled with the desired data. However, I fail in my attempt to place the Office data in the next column. Instead, the data continues to populate the cells under the Solicitor_Name column. How do I format the code so that I can get my desired output that looks like this? Solicitor_Name Offices Address John Orange LLP 123 Main St Bill Apple LLP 124 Bone St here is my views.py def law_view(request, *args, **kwargs): all_data = combine_data() return render(request, "law.html", {'all_data': all_data}) JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)
Solicitor_Names Offices Addresses Primary_Role Secondary_Role Other_Role Other_Role_1 Other_Role_2 Other_Role_3 Other_Role_4
{{ name }}
{{ office }}

1 Answer

0 votes
by
You have to construct your table row by row, not column by column. That also means that all_data should be a list of rows, not a dictionary of columns (which it seems to be now). So you want to construct all_data like this: [ {'name': 'Mr. Shaw', 'office': 'Orange LLP', 'address': '123 Main Str'}, {'name': 'Bill', 'office': 'Apple LLP', 'address': '124 Bone St'}, ... ] instead of like this: { 'name': ['Mr. Shaw', 'Bill', ...], 'office': ['Orange LLP', 'Apple LLP', ...], 'address': ['123 Bone St', ...] } If you're sure the lengths of your lists are all the same (it looks like it), you can transpose the second format to the first using: all_data = [{'name': all_data['name'][i], 'office': all_data['office'][i], ...} for i in range(len(all_data['name']))] or there's surely a function on DataFrame to do this (transpose()?) Then in your template you just have one loop: {% for solicitor in all_data %} {{ solicitor.name }}{{ solicitor.office }}... {% endfor %}

Related questions

0 votes
    I am a bit puzzled by the following code: d = {'x': 1, 'y': 2, 'z': 3} for key in d: print key ... Python? Or is it simply a variable? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    How can someone access the index itself for a list like the following : intg = [8, 23, 45, 12, 78, 90] When ... 1 to 6 in this case? Select the correct answer from above options...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    If I use a while loop for my below code, it is not giving the desired output, but when i use for loop i am anle ... x += 1 print(Comm) Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    tl;dr How to autofill an editable form with information stored in database Hey, Im creating a profile page ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    So, I started learning to code in Python and later Django. The first time it was hard looking at tracebacks and ... your Django code? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    In the Django model QuerySets, I see that there is a __gt and __lt for comparative values, but is there a __ne/!= ... (a=true, x__gt=5) Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    My Django app is unable to see MEDIA directory. When I run one of my views I need to open a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    Is Django an important source to learn? Is it important in future? Can I grow with it? So questions: Can ... can work on Django? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    Is there a way to declare a constant in Python? In Java we can create constant values in this manner: ... declaration in Python? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    How can I check the file going to be written exists in the directory, and if not , How can I create directory ... " flag for the same? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    I have the dataset that has the no_employees column that is the str object. whats is a best way to create the new ... 1-5 |Very Small Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I need to know how to use the delete_channel command in discord.py may someone please post a code sample ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I need to know how to use the delete_channel command in discord.py may someone please post a code sample ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 10, 2022 in Education by JackTerrance
0 votes
    People including me know there is something in Python called __future__ and it appears in quite a few modules I read. ... am I right? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I've recently seen quite a bit of the following pattern in Python: class Foo: pass class Bar: ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
...