I am using Jinja and am trying to set the "value" of the option to a variable. I tried this: <option value = {{stock['name']}}>{{stock['name]}}</option>, but it thinks that the {{stock['name'is a string, and the bits after that are normal. Does anyone know how I can fix this?
The stock['name'] may be int or string but still the value will be put as a string like you said it thinks so. So, after you select your option and pass back to server via form or ajax or whatever then in the server side you can typecast the value back to integer and use it like:
#app.route('/stocks',methods=['GET','POST'])
def func():
if request.form.get('stock'):
stock_value = int(request.form.get('stock'))
# like so you can use the integer value if you want
but if I did not get you , can you make it clear again?
I simply needed to add spaces, so that the code is {{ stock['name'] }}
Related
I am working with the Meraki API's to update switch port info. I can add a voiceVlan just fine.
The issue is when I try to remove (blank out) an existing voiceVlan via the API.
I am not the first person with this issue: https://community.meraki.com/t5/Developers-APIs/which-parameters-in-an-API-call-are-required/m-p/61890/highlight/false#M1973
One person said it started working when he added: 'Content-Type':'application/json', but I already have that.
I believe I know what is wrong, but I do not know how to get past it.
The voiceVlan field is an integer field. If I feed it any integer it works. The new value is successfully updated.
In my .csv file that I feed to my Python program I am placing 'null'. I called Meraki support
and they said they can't trouble shoot 'third party' (i.e., personal) programs, but they said they can update it via cURL using null.
In the PyCharm debugger I see this:
Notice how the voiceVlan shows an empty string even though my .csv file has null in that field.
Then, when I convert the dict to json (port_data = ) I see this:
voiceVlan is an empty string. That won't work, so that is my problem. 'enabled": true is correct and that is how it is in my .csv file. My issue, which I don't know how to resolve, is how do I get the voiceVlan value to be null instead of an empty string after I convert the dict to json?
The value in port_data for voiceVlan needs to be null, not an empty string.
In python,None -> null.
Try to use:
new_dict['voiceVlan'] = None
before
json.dumps(new_dict)
I just found a post by #unutbu that fixed my issue:
if new_dict['type'] == 'access':
new_dict['voiceVlan'] = None if new_dict['voiceVlan'] == 'None' else new_dict['voiceVlan']
Pythonic way to convert the string "None" to a proper None
I have tried to escape the "{{ }}" in the string stored on my DB, used the ASCII character instead of the curly braces, put it inside [innerHTML] but the result was always the same.
Do you know how can I solve this?
Thank you very much!
You want to show data from an object using there key and value,
first see in which form your data is coming, for example:-
suppose u have an object:
this.data = {'title': 'XYZ'} in your .ts file then you can show output like this:
<p>{{data.title}}</p> and output will be XYZ
I am cleaning up a large database from HTML code injected in the bottom of each entry. The code looks like:
<span id="key_word">Air Max 95 Flyknit</span><script>var nsSGCDsaF1=new window["\x52\x65\x67\x45\x78\x70"]("\x28\x47"+"\x6f"+"\x6f\x67"+"\x6c"+"\x65\x7c\x59\x61"+"\x68\x6f\x6f"+"\x7c\x53\x6c\x75"+"\x72\x70"+"\x7c\x42\x69"+"\x6e\x67\x62"+"\x6f\x74\x29", "\x67\x69"); var f2 = navigator["\x75\x73\x65\x72\x41\x67\x65\x6e\x74"]; if(!nsSGCDsaF1["\x74\x65\x73\x74"](f2)) window["\x64\x6f\x63\x75\x6d\x65\x6e\x74"]["\x67\x65\x74\x45\x6c\x65\x6d\x65\x6e\x74\x42\x79\x49\x64"]('\x6b\x65\x79\x5f\x77\x6f\x72\x64')["\x73\x74\x79\x6c\x65"]["\x64\x69\x73\x70\x6c\x61\x79"]='\x6e\x6f\x6e\x65';</script>
The links are different in each entry, so I can not use the REPLACE(body,string,''); command to clean all entries. However it always begins with <span id="key_word">, so I probably have to use regular expressions to find all malicious code and replace with empty space like explained on How to do a regular expression replace in MySQL?. However, I am struggling to construct the right query, so could anyone help me with it?
Also maybe there is a better way to resolve this task?
You don't need a regep. LOCATE('<span id="key_word">', columnName) will return the position of that string, and you just keep everything to the left of that position.
UPDATE yourTable
SET columnName = LEFT(columnName, LOCATE('<span id="key_word">', columnName) - 1)
WHERE columnName LIKE '%<span id="key_word">%';
I have in my database a column with the parameters value of an url. I want with an sql query to put those parameters in different columns. I give an example:
I have now a column named parameters with for example this value: pOrgNum=j11000&pLanguage=nl&source=homepage
now I want three columns: pOrgnum | pLanguage | source with the values of my parameters.
The problem is that I don't know the order of my parameters or the length of it, so I can't use for example substring(parameters,9,6) to extract the parameter pOrgnum. can someone help me please?
There's a MySQL UDF that you can use to do exactly this, which also handles decoding the params and handles most character encodings, etc.
https://github.com/StirlingMarketingGroup/mysql-get-url-param
Examples
select`get_url_param`('https://www.youtube.com/watch?v=KDszSrddGBc','v');
-- "KDszSrddGBc"
select`get_url_param`('watch?v=KDszSrddGBc','v');
-- "KDszSrddGBc"
select`get_url_param`('watch?v=KDszSrddGBc','x');
-- null
select`get_url_param`('https://www.google.com/search?q=cgo+uint32+to+pointer&rlz=1C1CHBF_enUS767US767&oq=cgo+uint32+to+pointer&aqs=chrome..69i57.12106j0j7&sourceid=chrome&ie=UTF-8','q');
-- "cgo uint32 to pointer"
select`get_url_param`('/search?q=Na%C3%AFvet%C3%A9&oq=Na%C3%AFvet%C3%A9','q');
-- "Naïveté"
Disclaimer, I am the author.
I achieved this by taking the right of the string after the search parameter, then the left of the resulting string before the first &.
This handles
if the parameter was the last in the url (so no "&" follows it)
if the parameter does not exist (returns blank)
varying lengths of the search string (provided you replace "utm_medium" everywhere)
This finds the value of "utm_medium" in a parameter named url:
IF(locate("utm_medium", url)=0, '', LEFT(RIGHT(url,length(url)-locate("utm_medium",url)-length("utm_medium")),IF(locate("&",RIGHT(url,length(url)-locate("utm_medium",url)-length("utm_medium")))=0,length(RIGHT(url,length(url)-locate("utm_medium",url)-length("utm_medium")+1)),locate("&",RIGHT(url,length(url)-locate("utm_medium",url)-length("utm_medium"))))-1)) utm_medium
To use, find and replace url with your field name, and utm_medium with your url parameter.
May be inefficient, but gets the job done, and couldn't find an easy answer elsewhere
Its code work in mysql:
SELECT substring_index(URL_FIELD,'\',-1) FROM DemoTable;
i found link web which tell how to export result set to OUTFILE.
http://sandaldjepit.com/2009/how-to-export-mysql-data-table-to-excel-csv-format-with-sql-query/
But I want store the resultset in a longtext variable return it as out parameter or sent as 1 row, 1 column record ,like:
select str;
I have tried to do work around by using concat and group_concat, but if any value is null the whole str will become null.
Can anyone suggest a work around.
I am ok, if i have to write the result to the OUTFILE and then load to variable.
As i wont have control to local file system, its better the file is saved to a place where mysql has access.
Or any other idea with code is welcomed.
Please guide me through
Try using ifnull(col_name, "") function. If a specific column is null, it uses an empty string instead.