Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm trying to use visual studio for my Django project. My visual studio version is 2017, my Python version is 3.6 and my Django version at the beginning is 1.1.18.
Then I upgrade it to 2.1.5. I make an app then add it to installed apps. But when I migrate the project get this error:
Traceback (most recent call last):
File "E:\Django_Try\Test4\Test4\manage.py", line 17, in <module>
execute_from_command_line(sys.argv)
File "E:\Django_Try\Test4\Test4\env\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "E:\Django_Try\Test4\Test4\env\lib\site-packages\django\core\management\__init__.py", line 357, in execute
django.setup()
File "E:\Django_Try\Test4\Test4\env\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "E:\Django_Try\Test4\Test4\env\lib\site-packages\django\apps\registry.py", line 89, in populate
app_config = AppConfig.create(entry)
File "E:\Django_Try\Test4\Test4\env\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'saeed'
The interactive Python process has exited.
The interactive Python process has exited.
it seems can' identify my app.
my setting:
Django settings for Test4 project.
Generated by 'django-admin startproject' using Django 1.9.1.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
import os
import posixpath
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '79c97724-a0e9-44f0-bffd-e255d60e5460'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
# Add your apps here to enable them
'saeed',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
#'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
ROOT_URLCONF = 'Test4.urls'
TEMPLATES = [
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
WSGI_APPLICATION = 'Test4.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = posixpath.join(*(BASE_DIR.split(os.path.sep) + ['static']))
–
Edit: It looks like you've renamed your main/base app (the one that contains settings.py
) from Test4
to saeed
. You do not need to register the base application in a Django project since it is already the entry-point for the program. It looks like the rest of your settings.py
file is configured for the base app being called Test4
rather than saeed
(you can tell because of ROOT_URLCONF = 'Test4.urls'
, for example). You can read more about projects and applications in Django here.
Since it's common practice to have your base app share the same name as your project I'd recommend changing the name of the saeed
directory (back) to Test4
.
If you want to create a new app you can run:
python manage.py startapp saeed
So your project file structure will look something like this:
Test4/ # project directory
saeed/ # your app
migrations/
models.py
apps.py
Test4/ # base app for the site
settings.py
urls.py
manage.py
requirements.txt
Then put your models in saeed
instead of Test4
. So your project directory Test4/
, will contain Test4/
, saeed/
, and manage.py
, among other things. After you create this new app, the following will work:
Original Answer:
Make sure your saeed/apps.py
is configured properly, for example:
# saeed/apps.py
from django.apps import AppConfig
class SaeedConfig(AppConfig):
name = "saeed"
verbose_name = "Saeed"
Then you'll want to change that line in INSTALLED_APPS
in settings from just "saeed"
to
"saeed.apps.SaeedConfig"
See the docs on configuring applications for more on this.
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.