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.
Related
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
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.
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?
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
If anyone knows how to solve this, please don't hesitate to help. I've tried many hints, but so far this problem still remains. Too frustrating!
I just started a little project on Django because I want to test Django Rest Framework. I created a project called project and inside it an app called user.
After that, I created a directory called api inside user and then I created the files viewsets.py and serializers.py in order to test Django Rest Framework.
In urls.py I imported "UsuarioViewSet" class from viewsets.
from project.user.api.viewsets import UsuarioViewSet
When I run python manage.py runserver the problem bellow ocurrs
(I also tried only user.api.viewsets... but it says "unresolved reference")
In my settings.py I registered 'user' and 'rest_framework':
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'user',
]
OS: Linux Mint |
IDE: PyCharm (community) |
Virtualenv: venv |
Python: 3.6.6
As far as I know, this kind of thing happens because of migration file __init__.py.
The main reason for this is when you write code and make changes in the migration file and then you remove some part from code for which a migrate file has been already created.
So a solution is just delete __init__.py from migration
and make sure that there is no other import which is removed or changed.