In my app.component.ts I import my webservices module as such:
But I'm getting red squiggly lines, even though I think I should be importing it correctly. Here's my app structure:
Here's my web service module:
Must be:
import {Webservice} from './webservices/webservices.services';
Related
Using Django 2.2, how can I run code once after the code has been loaded but before any request is handled? (Similar to code executed in Rails initializers).
The use case is the following:
I'd like to create a pool of connections to a database and assign it to a global variable in a module but preferably not during module import.
(Initially following: https://stackoverflow.com/a/1117692/3837660, I was doing it at module import. But this is not optimal. Partly because I am facing a double import issue which I haven't solved yet and partly because I'd like to avoid creating a pool of connections at module import time.)
It should be done exactly once (no matter if that module happens to be imported twice) but at the application start (not on the first request).
=============================
EDIT:
Apparently running
python manage.py runserver localhost:8000
will call manage.py main twice. As a consequence, everything is imported twice and the ready function is also called twice.
I think you can take advantage of the django AppConfig, docs here -> https://docs.djangoproject.com/en/2.2/ref/applications/#django.apps.AppConfig
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _
class YOURAPPNAMEConfig(AppConfig):
name = 'YOURAPPNAME'
verbose_name = _('VERBOSE APP NAME')
def ready(self):
CODE YOU WANT TO RUN ON APP READY
Let us know if this helps you.
I am going through the official tutorial provided by graphene-python for their library.
I, like a few others I have seen online, am having some serious issues trying to simply import the schema file within the project folder (project_name/schema.py). For reference, the project_name is cookbook as it is denoted within the tutorial.
This is within my settings.py:
GRAPHENE = {
'SCHEMA': 'cookbook.schema.schema'
}
and this is in the schema file tiself (project_name/schema.py):
import graphene
import cookbook.schema
class Query(cookbook.schema.Query, graphene.ObjectType):
# This class will inherit from multiple Queries
# as we begin to add more apps to our project
pass
schema = graphene.Schema(query=Query)
The error that I am getting is:
Could not import 'cookbook.schema.schema' for Graphene setting 'SCHEMA'. AttributeError: module 'cookbook' has no attribute 'schema'.
I have also tried a few other tutorials as well, but haven't had any luck. My project is on django 2.0.2 and graphene 2.0.1. Any help would be much appreciated.
Did you add this to your installed apps?
INSTALLED_APPS = [
'graphene_django',
]
the error says that cookbook has no attribute schema.
Therefore the import cookbook.schema is not working in your schema.py
the example says
import cookbook.ingredients.schema
I actually had incompatible versions of Django, Graphene and Django-environ.
To solve, I made a virtualenv using mkvirtualenv. After that, I was able to follow this tutorial without any issues. It is capable of being stood up without a virtual environment, but it was far easier to just define one and get moving with a clean slate.
I'm trying to import a model from another app.
I have a folder named "apps" where all my applications live.
so in the models.py of app2, i have the line:
from apps.app1.models import Book
but for some reason, i get the "No module named app1.models" error.
I'm using django1.9 if that matters.
Any advice?
Thanks.
I think from ..app1.models import Book will help you. It's a var of relative path to import.
I have to port a non-cli project to the cli. I have a route that is:
App.thisRoute = App.previouslyDefinedRoute.extend({...})
With the CLI, I've tried this:
// routes/thisRoute.js
import App from 'app';
export default App.previouslyDefinedRoute.extend({...})
That gives me this Ember Inspector Error:
Ember Inspector has errored.
...
Error message: Could not find module app imported from app/routes/thisRoute
I've also tried:
// routes/thisRoute.js
import App from 'routes/previouslyDefinedRoute.js';
export default App.previouslyDefinedRoute.extend({...})
Both dont work.
How do I get my app instance?
There is no app instance in ember-cli, it uses ES6 modules instead, in order to extend a route you will have to import it first.
import PreviousRoute from 'yourProjectName/routes/previouslyDefinedRoute';
Note that the file extension is not needed.
And then you can just export default PreviousRoute.extend({});.
Your files must always export either a default or a named function in order to be used by other files.
I have two apps login and someother
I am trying to import a function like
From login.views import save
In someother.views.py
But getting ImportError: No module named views
I found the answer to my question.
Here it is.
My app name was "login" and have feature.py in the same.
when i tried to import feature using
from login import feature
IDE was not showing any issues. intellisense was working fine.
but when i tried to runserver it thrown ImportError: No module named feature.
and as soon as i changed login to extended_login it worked.
So i think some Keywords are not acceptable as app names or there is already a (system) app named with that keywords which actually do not have a module you trying to import.