I am trying to import a small json file that contains various strings that the program uses.
I can do a successful import:
import * as dwSTRINGS from './data/strings.json';
But cannot seem to reference the variable dwSTRINGS.
How do reference imported variables?
Related
I have a FastAPI web app, where I would like to use a templating language.
Right now, in order to use jinja2 I have to indicate where the templates folder is located by setting a templates variable like this:
templates = Jinja2Templates(directory="templates")
I also have several view files for various pages and purposes, like home.py, about.py, db.py etc.
If I set up a templates variable once in main.py and then import it into view files like this:
from main import templates
I get all kind of circular import errors. So I have to set up a templates variable in every view file separately which is not optimal.
How can I set templates location once in the main.py and then make all view files aware of this location?
There are many ways you can solve this - move the template configuration to a separate file instead of having it in main (templating.py or define it in __init__.py in your views directory) so that you can import it from that module instead. A plain import would work in that case.
You can also use the dependency injection feature in FastAPI to inject the templating context in a view function.
Set it up as a Depends construct in a separate file (dependencies.py, app_services.py, __init__.py or wherever):
def get_templates():
return Jinja2Templates(directory=...)
And then in your views:
from dependencies import get_templates
...
#router.get('...')
async def display_xyz(templates: Jinja2Templates = Depends(get_templates))
I wanted to import data to my collection in mongodb atlas, and I was following the documentation: https://docs.mongodb.com/compass/beta/import-export/ but there is no "ADD DATA" and I don't know if Im using some other version or Im doing something else wrongly.
I need to import whole file which is json array.
The docs you referenced are for a future version of Compass. If you want to import from EJSON at the command line you can use mongoimport.
Here's the simplest syntax, but there are many variations possible.
mongoimport --db=users --collection=contacts --file=contacts.json
I have a file called src/services/data.json which I use to populate some data for one of my services. I use the following
import embeddedData from "./data.json";
to import the file. When I generate the distribution, as expected the contents are merged in so they're not in the resulting dist folder
Is there something I can do to the webpack configuration so it will export JSON data files? (I'm using vue with TypeScript for my framework)
I would go with Dynamic Imports. Webpack will create separate files for such imports by default. In runtime those files are asynchronously loaded. Webpack
transforms import() calls to Promises so you can use await/async as well.
Im using DHIS 2 Live with embedded database.
I have and excel, with some data, i transformed it to csv and tried to import it using the import tools.
ImportTools
ImportExample
It doesnt print any error just stop and does not insert anything.
I tried to import some data in json too but i dont know if i should import it like data or meta data.
I have a large csv file of lat/long points that I would like to import into Parse into a class that has already been created with existing lat/long points. Unfortunately parse does not allow you to import "Geopoints" with their CSV import tool. They only let you import that standard data sets. (Strings, Arrays, Booleans etc.) Does anyone know of a way to import them into an existing class? Thanks.