import module issue in a Django project: error ModuleNotFoundError - modulenotfounderror

OS: Ubuntu
Django 4.1.6
I run into a very unexpected issue. I have created a Django project named data base. In this project I have created several apps (administrative, api, real_estate, telegram_app ...) with python manage.py startapp <app_name> inside the root folder.
Project structure with apps
I have added each app on the settings INSTALLED_APP.
settings.py file
Each of my apps apart from api and telegram_app have models. I have created in each app the corresponding admin.py.
After creating a New sqlite data base and the superuser i Can go to my admin site and manage each model of each app.
admin site with all modules models
So far so good then. My issue Come later. Now I want my telegram app and my api app to access models from other apps. So nothing wierd or fancy here.
But when I import model to use it I run into the error no module with that name.
error No Module name
Andy help?
I tried to change the import from database.api to api with the same result:
error 2
and also from ..api:models import but with the same result

Related

created an app called users ,want to use "from users import views as v" .Already made changes in settings.py file. But it says unreferenced error?

from users import views is not working
I created two apps. the first one works fine. The same way I created another app called as users. But when I import it, it says unreferenced error. I already added it in installed apps in the main settings.py file of the project.
There are two apps. The first one is working fine. The second one is giving error when I import it. It says unreferenced error
Change url :
add urls.py in users.
and add this line:
from user import views as v_register
and add this line in blog url.
path('users/', include(users.urls)),

attempted relative import with no known parent package on Google AppEngine with Python3.7

Getting the following error:
"/srv/server.py", line 12, in from .routes.solver import route as solve ImportError: attempted relative import with no known parent package
Deploying the app to AppEngine Standard env, and my project looks like so:
---/
|_app.yaml
|_server.py
|_routes
|_solver.py
In server I do from .routes.solver import route as solve and get the above error in GCP, but not locally.
I tried https://stackoverflow.com/a/16985066/483616 and a few others. Tried with __init__.py at pretty much every level and every location. Then saw that it wasn't needed for python3, so removed. Pretty much unsure what to do now.
Not optimistic that this is the answer but just to throw it into the pot, have you seen Problem with Python relative paths when deploying to Google App Engine Flexible ?

How to import models from other sibling app in Django

i create a project in django
in this project i am use the no. of app like
home ,payment
i am create some models in home/model.py file
and i want to use this model as a ForeignKey in payment/model.py file but i can't access and implode that file on this location i am using no. of method but it's give me some error.
show please help me how to access this file on this location
Thank You
This is how you can import your models module from CoupoonCode library
from home.models import CoupoonCode

Google Cloud Console - Flask - main.py vs package

OK, so I have been through some tutorials to get a flask app onto google cloud, which is fine.
I have also been through the flask tutorial to build a flaskr blog:
http://flask.pocoo.org/docs/1.0/tutorial/
It occurred to me that a sensible thing to do would be to create a database (MySQL in mycase) on google and then modify the code so that it uses that. This is fine and I can get it to work on my local machine.
However, now that I am coming to deploying this, I have hit a problem.
The google cloud tutorials tend to use a flask app that is initiated in a single file such as main.py, eg:
from flask import Flask, render_template
app = Flask(__name__)
....
The flask tutorial mentioned above uses a package and puts the code to create_app() in the __init__.py file and at present I cannot get this to start in the same way. (see sample code).
from flask import Flask
def create_app(test_config=None):
# create and configure the app
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(
SECRET_KEY='dev'
)
Are there some adjustments that I need to make to something like the app.yaml file to get it to recognise flask as the flaskr package or do I need to rewrite the whole thing so that it uses a main.py file ?
I feel that this is one of the points in time where I could really pick up a bad habit. What in general is the preferred way to write flask apps on google cloud ?
I am using the standard environment in google.
Thanks for your advice.
Mark
Since you have an application factory, you can create the app anywhere. Just create it in main.py, since this is what App Engine expects:
from my_package import create_app
app = create_app()

Python2 connexion framework - controller in directory structure

I am playing around with using the connexion framework to setup a REST API access for my application.
My application is is built on python2, I installed the connexion framework for python2 and played around with the yaml file via the editor (editor.swagger.io). I downloaded the Python Flask server code, converted it to be compatable with Python2 and tested for a single controller.
When the controller is placed in the same directory as the place where the server is run. Everything was fine - all routes were added and working as expected. I then proceeded to split the controller based on some business logic and wanted a tree structure for each controller.
Something like
myapp/api/magic1/magic1_controller.py
myapp/api/magic2/magic2_controller.py
and so on.
This does not work for python2. It seems to work for python3. Any ideas why?
I get the following error from logs
DEBUG:connexion.api:Security Definitions: {}
DEBUG:connexion.api:Validate Responses: False
DEBUG:connexion.api:Creating API blueprint: /api
DEBUG:connexion.api:Adding swagger.json: /api/swagger.json
DEBUG:connexion.api:Adding swagger-ui: /api/ui/
DEBUG:connexion.api:Adding /api/magic1/{name}...
ERROR:connexion.api:Failed to add operation for GET /api/magic1/{name}
In the yaml config file I add the OperationId as api.magic1.func1() and so on.
Following the information you provided here the operationId should be set to api.magic1.magic1_controller.func1 and not api.magic1.magic1.func1().
You are missing to provide more details about your problem. Code snippets would help to guide you in a more detailed solution.

Resources