I would like to use an api key stored in an environment variable. I know I can just put it directly in the html (I don't think it is bad security wise since it is a public key). But I can't get access it an my react component.
useEffect(()=>{
SetRecaptchaKey(import.meta.env.VITE_SITE_RECAPTCHA_KEY);
console.log(recaptchaKey)
});
outside my component function (above) I have this:
const key = import.meta.env;
console.log(key)
it logs the object in the console, and it has the variable i'm looking for.
Another thing, is that I have two VITE_... variables and another variable. Only one of VITE_.. is loaded (which is what I want) but I don't understand why.
Thanks in advance
In order to use an environment variable in client side Astro, you need to prefix the variable with "ASTRO_". For example, if you have an environment variable named "TEST_VAR", you would access it in client side Astro as "ASTRO_TEST_VAR".
Related
https://www.twilio.com/docs/studio/widget-library#run-function
When you invoke a Function, you have two possible options for using variables: (1) you can pass Flow variables as parameters into a Function (e.g. flow.data.foo), and (2) you may set Flow variables with data returned from the Function (TwiML or JSON can be returned).
Does anyone know how to set Flow variables with data returned from a Function?
You should be able to follow the Liquid Syntax documented here, to do so.
Liquid Template Language - Assigning Variables
https://www.twilio.com/docs/studio/user-guide/liquid-template-language#variable-assignment
Or just call the returned variable by addressing the Function widget as shown at the link below:
https://www.twilio.com/docs/studio/widget-library#run-function
widgets.MY_FUCTION_WIDGET_NAME.parsed.xxxxx (where xxxxx is the JSON path).
Alan
I know how we can declare global variable in config file and then access through
Service Locator
Currently I am getting this Global variable in controller with the help of service locator and then pass it to models while creating object.
Question: Is it possible that I can get the Global variable in model directly rather than passing in all the models through controller?
Yes it is possible to get the variable declared in global file into model directly. Instead of declaring it as variable, just define it as constant in the global file so that you can access that variable easily in any models.
define('VAR_NAME',Value);
and access the variable using.
constant('VAR_NAME');
Hope it helps
Thanks
Hi im currently trying to get a value from my view and store it in a global variable declared in my hub.
so that i can use it throughout my hub
however i have no idea how to sen the value from my view to the hub and store it in a variable in my hub
using Signal R
Example:
View: value=1
hub: int id
I am not sure I quite follow your question, but you can simply from your View call a method on a SignalR client and pass the value as a parameter. Server side, from within the handling method for the call, you could set the global variable in your hub?
Louis
If I have a variable name("x" for example) stored in another variable (varname in this example) I can create a global variable via
_G[varname]=42
This is a complicated way to say
x=42
Now I want to do the same thing for local variables. Is it possible?
No, because local variables are not stored in a table, or in any structure which associates their name to them. When the lua code is compiled into bytecode, local variable names turn into numeric offsets on the lua stack.
If you really need to use a string to modify local variables, your best option is using a local table.
local localVars = {}
function setValue(varname, value)
localVars[varname] = value
end
function getValue(varname)
return localVars[varname]
end
You are not really creating and destroying local variables this way, but you get pretty close.
I need a global variable that I can call from the templates.
I edited app_globals.py in lib directory to declare PATH_TO_IMAGES like this
class Globals(object):
"""Container for objects available throughout the life of the application.
One instance of Globals is created during application initialization and
is available during requests via the 'app_globals' variable.
"""
PATH_TO_IMAGES = ""
def __init__(self):
"""Do nothing, by default."""
pass
Now I can call from any template the image path like this
<img src="${g.PATH_TO_IMAGES}/${p.image}" />
The image path is stored inside a settings table on the app's database, but I can't initialize it from Globals declaration, i get this error:
sqlalchemy.exc.UnboundExecutionError:
Could not locate a bind configured on
mapper
Mapper|Settings|settings,
SQL expression or this Session
My guess is that database binding happens after Globals is initialized. So my questions is, which is the best place to initialize a global variable in TurboGears 2 and which is the best practice to that.
Just use a cached property:
class Globals(object):
"""Container for objects available throughout the life of the application.
One instance of Globals is created during application initialization and
is available during requests via the 'app_globals' variable.
"""
#property
def PATH_TO_IMAGES(self):
try:
return self._path_to_images
except AttributeError:
self._path_to_images = db_session.query(XXX) # Fill in your query here
return self._path_to_images
PS : your question is a generic Python question really. I suggest you read the official Python docs before posting other similar questions.
You probably need to create your own database connection to get this data from the database.
In SQLAlchemy terms, you'll want to create your own engine, session, etc. Just make sure to clean up after you're done.
I would probably do this in app_cfg.py using on_startup to get it into the config, and then stick it in the Globals object later on if you still need to.
You may set PATH_TO_IMAGES to it's definite value once the models are initialized. The sooner being at the end of the 'init_model' function declared in model/init.py.