python django only the first statement statement can be accessed

2024/7/8 6:13:26

i can acccess only the first statement in my name app

javascript:

<script type="text/javascript">function searched(){{% for names in name %}nameSearched = document.getElementById('name').value;document.getElementById('dis').innerHTML = nameSearched;if (nameSearched == "{{ names.First }}" ){document.getElementById('dis').innerHTML = "{{ names.Last }}";} else {document.getElementById('dis').innerHTML = "none";}{% endfor %}}
</script>
Answer

The problem is your function searched() in the script-tag.

If you have for example following name-instances:

[{'First': 'foo','Last': 'bar',},{'First': 'foobar','Last': 'barfoo',}
]

So your rendered if-else in the function would look like this:

function searched(){nameSearched = document.getElementById('name').value;if ("foo" == nameSearched) {...} else {...}if ("bar" == nameSearched) {...} else {...}
}

So as you can see, you are always running into the else if you entered foo.

What you could do is the following in your for-loop:

 <script type="text/javascript">function searched(){nameSearched = document.getElementById('name').value;{% for names in name %}{% if forloop.first %}if ("{{ names.First }}" == nameSearched) {document.getElementById('dis').innerHTML = "{{ names.Last }}";}{% else %}else if ("{{ names.First }}" == nameSearched) {document.getElementById('dis').innerHTML = "{{ names.Last }}";}{% endif %}{% endfor %}{% if name %}else {document.getElementById('dis').innerHTML = "none";}{% endif %}}
</script>

This would result in the following:

function searched(){nameSearched = document.getElementById('name').value;if ("foo" == nameSearched) {...}else if ("foobar" == nameSearched) {...}else {...}
}
https://en.xdnf.cn/q/120357.html

Related Q&A

syntax error return outside function in python

I am trying to count the word fizz using python. However it is giving me an error.def fizz_count(x):count =0 for item in x :if item== "fizz":count=count+1 return countitem= ["fizz",…

How to replace values in multidimensional array?

I am trying to get a multidimensional array working, where the user string is filled in the cell. I have been searching for ways to update user values in the multidimensional array def createMultiArr…

How to deploy a python docker image to AWS Lambda?

I am trying to figure out how to deploy a flask application that I have received with a Dockerfile to AWS Lambda.In local, all I have to do to start the app is to enter docker-compose up. Thats work gr…

How to isolate titles from these image URLs?

I have a list of image urls contained in images. I am trying to isolate the title from these image urls so that I can display, on the html, the image (using the whole url) and the corresponding title. …

Columns and rows concatenation with a commun value in another column

In the below mentioned table, I want to concatenate the columns Tri_gram_sents and Value together and then all rows which has the same number in column sentence.Tri_gram_sents Value …

Python Indentation Error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar q…

Allow form submission only once a day django

I want to allow users to submit a django form once, and only once everyday. After submitting the form, the form wouldnt even show (server-side checkings, I dont want to use JS or client side thing; eas…

Counting percentage of element occurence from an attribute in a class. Python

I have a class called transaction that have these attributes Transaction([time_stamp, time_of_day, day_of_month ,week_day, duration, amount, trans_type, location])an example of the data set is as sucht…

AWS | Syntax error in module: invalid syntax

I have created python script which is uploaded as a zip file in AWS Lambda function with stompy libraries bundled in them.Logs for python 2.7:-Response: nullRequest ID: "c334839f-ee46-11e8-8970-61…

Algorithm for finding if an array is balanced [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable…