ModuleNotFoundError: No module named 'menu' - python

I'm developing a django application, but when I try to start the server, I get an error: ModuleNotFoundError: No module named 'menu'.
Here is my code in settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'menu',
]`
```
Here is the project structure:
My files
I don't understand what I'm doing wrong.

Add this in your project's urls.py file if you didn't have done yet:
from django.urls import path, include
urlpatterns = [
path('', include('menu.urls')),
]
herehere is the same answer available it might help you

Related

Can't import rest_framework in Django despite it being installed in my venv

Following tutorials and I cannot import rest_framework.
I've activated my venv, run python and import rest_framework as suggested in many discussions on stack overflow, though no errors are thrown. I am fairly confident that djangorestframework is installed as it is in the environment directory:
venv dir shows rest_framework installed
I also restarted VS Code and my venv as suggested to no avail.
The error I receive in VS Code:
Import "rest_framework" could not be resolvedPylancereportMissingImports
Settings.py:
INSTALLED_APPS = [
'corsheaders',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'EmployeeApp.apps.EmployeeappConfig',
'rest_framework',
]
Immediately below INSTALLED_APPS:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
),
}
After setting up this project on my desktop it seems I have gotten it working. Though I selected my Python Interpreter path on my laptop, it seems that I may have done something wrong there on my laptop.
ctrl + shift + p
Python: Select Interpreter
select the path which includes the environment you are working with.

Issue importing modules with Django, but runs fine when I run it independently using '-m' flag

Currently I have a python project with the following directory structure.
I can run the demo.py file directly fine (without importing it in my Django project) from the outermost directory shown above using the following command:
python -m ObjectSegmentation.segmentation_api.apps.tools.demo
However, in my Django project, I need to import the demo.py file in my django views.py file, but when I do so, I get the following error:
from ObjectSegmentation.segmentation_api.apps.tools.test import *
ModuleNotFoundError: No module named 'ObjectSegmentation'
These are the first few lines from demo.py (including line 4) where the error occurs.
My installed apps in settings.py for the whole project look like this:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'apps.tools.demo',
'rest_framework'
]
How can I make it so that the imports work with both the project run independently and imported in my django project?

ModuleNotFoundError: No module named 'django.contrib.staticfilesbase'

Every time I try to run my program using python manage.py runserver, this same error comes up:
"ModuleNotFoundError: No module named 'django.contrib.staticfilesbase'"
This error typically means that while trying to run your app, either your code or your dependencies is telling django to look for django.contrib.staticfilesbase and my best guess is that it is your code.
Start with your settings.py. Open it and look under the installed apps. It should look at least something like this:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles', #this is probably where the mistake is
]
You can have other app under the "installed apps" ofcourse, but if you find django.contrib.staticfilesbase in there, change it to django.contrib.staticfiles.

Django app not recognized when inside another module

I have a project with a structure like this:
my-django-project/
venv/
.gitignore
README.md
my_django_project/
db.sqlite3
manage.py
my_django_project/
settings.py
my_first_app/
__init__.py
inside_app/
__init__.py
apps.py
serializers.py
models.py
views.py
...
In settings.py i loaded the app like this:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'my_first_app.inside_app',
]
Running py manage.py runserver gives the following error:
File "C:\Users\\Documents\GitHub\tin_api_v2_test\venv\lib\site-packages\django\apps\config.py", line 246, in create
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Cannot import 'inside_app'. Check that 'my_first_app.inside_app.apps.InsideAppConfig.name' is correct.
However, it works fine when I don't use the Virtualenv. I've also tried putting the venv inside the django project folder to see if that would change anything but it didn't work.
Solved it..
In apps.py of inside_app i had to change from:
from django.apps import AppConfig
class InsideAppConfig(AppConfig):
name = 'inside_app'
to
from django.apps import AppConfig
class InsideAppConfig(AppConfig):
name = 'my_first_app.inside_app'

ModuleNotFoundError: No module named 'impassionuser'

I'm using django on vscode, and typed this on terminal:
(impassion) Subinui-MacBook-Pro:impassion_community subin$ python3 manage.py makemigrations
but can't use makemigrations
got this error message
ModuleNotFoundError: No module named 'impassionuser'
how can I solve this problem?
I'm using MacOSX, VSCode, django
and setup virtualenv
I expected to see follow messages
Migrations for 'impassionuser':
impassionuser/migrations/0001_initial.py
-Create model impassionuser
In settings.py, I already added 'impassionuser'
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'impassionuser',
'board'
]
Did you register your model in admin.py.
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
from .models import mymodel
admin.site.register(mymodel)
Hopefully this will help.
Also check this Django Tutorial

Categories