logo
down
shadow

Couldn't iterate over a dictionary context variable in template, despite having all in place, as far as I know?


Couldn't iterate over a dictionary context variable in template, despite having all in place, as far as I know?

Content Index :

Couldn't iterate over a dictionary context variable in template, despite having all in place, as far as I know?
Tag : python , By : THD
Date : December 01 2020, 05:00 PM

Does that help The third argument to render is a "context", a dictionary whose keys will be available to your HTML as names. You're passing your table object as the context, so its keys (like i04) are available as variables... but there is no key named table in your table, so the name table isn't available to your HTML.
Change this line in view.py:
return render (request,"sudoku.html",table)
return render(request, "sudoku.html", {"table": table})
import logic
render(request, "sudoku.html", logic)

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

how to iterate through dictionary in a dictionary in django template?


Tag : python , By : Gabe
Date : March 29 2020, 07:55 AM
it should still fix some issue Lets say your data is -
data = {'a': [ [1, 2] ], 'b': [ [3, 4] ],'c':[ [5,6]] }
<table>
    <tr>
        <td>a</td>
        <td>b</td>
        <td>c</td>
    </tr>

    {% for key, values in data.items %}
    <tr>
        <td>{{key}}</td>
        {% for v in values[0] %}
        <td>{{v}}</td>
        {% endfor %}
    </tr>
    {% endfor %}
</table>
{% for key, value in data %}
    <tr>
        <td> Key: {{ key }} </td> 
        <td> Value: {{ value }} </td>
    </tr>
{% endfor %}

Iterate over one key's dictionary in another dictionary in a Django template


Tag : python , By : Murali Ravipudi
Date : March 29 2020, 07:55 AM
like below fixes the issue In Django templates, you cannot use the data['today'] syntax to access the value of a dictionnary, you need to use the . (data.today):
{% for key, value in data.today.items %}
    {{ key }} {{ value }}
{% endfor %}

Not able to access context dictionary values using variable key using filter in Django template


Tag : django , By : AdrianB
Date : March 29 2020, 07:55 AM
seems to work fine Since c is a context, it is not directly available in the template. What is available are the keys/values you set in the context i.e. If your context is like following:
 c = {'dbs':[u'db1', u'db2'], u'db1' : [u'tb1', u'tb2'], u'db2' : [u'tb21', u'tb22']}
def DBConnect(request):
    c = {}
    dbs = get_all_db() #returns an array of db.
    c['dbtbls'] = {db: get_all_tables(db) for db in dbs}
    return render_to_response('test.html', c)
{% for db, tbls in dbtbls.items %}
     do something with {{ db }} here.
     {{ tbls }} # this is the list of all the tables in the db
{% endfor %}

Custom template tage taking context: why is context a RequestContext instead of a dictionary?


Tag : python , By : jaset
Date : March 29 2020, 07:55 AM
I wish this help you RequestContext implements the dictionary interface. It is the same as that passed from the view which you normally use in the template. You just access your items like any other dictionary, and context['obj'] will work fine.

Iterate a dictionary in dictionary in django template


Tag : python , By : ianium
Date : March 29 2020, 07:55 AM
seems to work fine
import json

strJson = '''
 <your JSON string>
'''

dictJson = json.loads(strJson)

# python 2.X
for key, value in dictJson.iteritems():
    print (value['content_details']['name'])

# python 3.X
for key, value in dictJson.items():
    print (value['content_details']['name'])
Related Posts Related QUESTIONS :
  • Ignore Nulls in pandas map dictionary
  • How do I get scrap data from web pages using beautifulsoup in python
  • Variable used, golobal or local?
  • I have a regex statement to pull all numbers out of a text file, but it only finds 77 out of the 81 numbers in the file
  • How do I create a dataframe of jobs and companies that includes hyperlinks?
  • Detect if user has clicked the 'maximized' button
  • Does flask_login automatically set the "next" argument?
  • Indents in python 3
  • How to create a pool of threads
  • Pandas giving IndexError on one dataframe but not on another similar dataframe
  • Django Rest Framework - Testing client.login doesn't login user, ret anonymous user
  • Running dag without dag file in airflow
  • Filling across a specified dimension of a numpy array
  • Python populating dataframe in pandas from text files
  • How to interpolate a single ("non-piecewise") cubic spline from a set of data points?
  • Divide 2 integers (leetcode 29) - recursion issue
  • Can someone explain why do I get this output in Python?
  • How do I scrape pdf and html from search results without obvious url
  • Is there a way to automatically make a "collage" of plots with matplotlib?
  • How to combine multiple rows in pandas with shared column values
  • How do I get LOAD_CLASSDEREF instruction after dis.dis?
  • Django - How to add items to Bootstrap dropdown?
  • Linear Regression - Does the below implementation of ridge regression finding coefficient term using gradient method is
  • How to drop all rows in pandas dataframe with negative values?
  • Most Efficient Way to Find Closest Date Between 2 Dataframes
  • Execution error when Passing arguments to a python script using os.system. The script takes sys.argv arguments
  • Looping through a function
  • Create a plot for each unique ID
  • a thread python with 'while' got another thread never start
  • Solution from SciPy solve_ivp contains oscillations for a system of first-order ODEs
  • trigger python events driven by selenium controlled browser
  • Passing line-edits to a contextmanager to set validators
  • Python: globals().items() iterations try to change a dict
  • Is it possible to specify starting values for each parameter (instead of bounds) for scipy's differential evolution?
  • why datetime.now() and constructed datetime using all fields(like year,month...) of now has big timedelta?
  • MySQL multiple table UPDATE query using sqlalchemy core?
  • find if a semantic version is superset of of another version python
  • Type checking against dynamically created objects
  • Struggling with simple reverse function
  • Is there a function for finding the midpoint of n points on sklearn.neighbors.NearestNeighbors?
  • How to set max number of tweets to fetch
  • PYTHON 3.7.4 NOT USING SQLITE 3.29.0
  • How to replace Nan value with zeros in a numpy array?
  • How to speed up calculating variance among sparse matrix
  • cupy code is not fast enough compared with numpy
  • How to count frequency of select values in Python pandas dataframe
  • Scrape Span Text from Google
  • Python watchdog, watch a directory and rename file on event.modification
  • Filtering rows in DataFrame with dependent conditions
  • How to check if a character is a not a part of number or URL in string?
  • Compare corresponding elements of a list
  • Python misinterprets 3 character string as UTF-8 continuation byte
  • Merge two columns in Pandas
  • Side Effect error in Python in an online compiler
  • How to convert a navigation list with depth levels to a parent-child flat list?
  • Retrieving values from a paired key dictionary in Python
  • How to test the current text of a Tkinter text box widget before inserting new text after user clicks on a button?
  • computing the Cumulative Sum, where Sum can be reset by a condition
  • Where do you specify your API key when making a request with the Google API python library?
  • Pandas DataFrame, computing the Time Difference between one row and other row which satisfies a condition
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com