I am using Django and trying to use Django Rest Framework as well.
Since I had never used Django Rest Framework, I did a kind of tutorial by following an article. To do this, I created a new app by entering python manage.py startapp app.
After I finished the tutorial, I deleted this app in order to work on my project.
However, when I try to make the server run I got this error.
(venv) (base) MacBook-Air-4:extra_exchange user$ python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/core/management/base.py", line 368, in execute
self.check()
File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/core/management/base.py", line 396, in check
databases=databases,
File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/core/checks/registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/urls/resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/urls/resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/urls/resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "/Users/user/opt/anaconda3/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/user/Desktop/my_project/extra_exchange/extra_exchange/urls.py", line 21, in <module>
path("api/", include("api.urls"))
File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/Users/user/opt/anaconda3/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'api'
On the very last line, it says No module named 'api'.
But as I said, I have already deleted this. I looked for solutions but all solutions tell about already installed files, not deleted files.
I would like you to teach me how to figure it out.
Before I deleted this api file, the structure of files is like this.
project
|
|- app
| |
| |- migrations
| | ...
| |- and everything
|
|- api(deleted folder)
| |
| |- migrations
| | ...
| |- and everything
|
|-my_project
| |
| |- setting.py
| | ...
| |- and everything
|
|-venv
|-manage.py
Actually, I forgot to remove some urls from urls.py, that's why I got the error.
Thank you for watching it. I figured it out.
I just spent almost an hour trying to figure out something similar myself.
I deleted all references to my app from my project but kept getting this error.
I searched the entire project in my IDE (VS Code) for references to the app, but didn't find any. (even reinstalled Django but no luck).
Finally I decided to do a grep within the project folder. Sure enough I found a reference. What happened was that I edited the file, but didn't save it.
Hopefully someone will benefit from my experience.
Related
I ran into this problem and searched many resources but couldn't find a solution. My Django project was running successfully on my local. But when I deployed it to the server, it kept getting the following error.
ModuleNotFoundError: No module named 'proj'
I installed all the required libraries and all the settings should be correct as they worked fine on my OSX.
(venv) [root#10-10-7-140 vanilla]# python manage.py runserver
Traceback (most recent call last):
File "/data/www/vanilla/vanilla/venv/lib/python3.8/site-packages/django/core/management/base.py", line 414, in run_from_argv
self.execute(*args, **cmd_options)
File "/data/www/vanilla/vanilla/venv/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 74, in execute
super().execute(*args, **options)
File "/data/www/vanilla/vanilla/venv/lib/python3.8/site-packages/django/core/management/base.py", line 460, in execute
output = self.handle(*args, **options)
File "/data/www/vanilla/vanilla/venv/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 81, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "/data/www/vanilla/vanilla/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 87, in __getattr__
self._setup(name)
File "/data/www/vanilla/vanilla/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 74, in _setup
self._wrapped = Settings(settings_module)
File "/data/www/vanilla/vanilla/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 183, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/python3.8/python3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'proj'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/data/www/vanilla/vanilla/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/data/www/vanilla/vanilla/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/data/www/vanilla/vanilla/venv/lib/python3.8/site-packages/django/core/management/base.py", line 427, in run_from_argv
connections.close_all()
File "/data/www/vanilla/vanilla/venv/lib/python3.8/site-packages/django/db/utils.py", line 212, in close_all
for alias in self:
File "/data/www/vanilla/vanilla/venv/lib/python3.8/site-packages/django/utils/connection.py", line 73, in __iter__
return iter(self.settings)
File "/data/www/vanilla/vanilla/venv/lib/python3.8/site-packages/django/utils/functional.py", line 49, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/data/www/vanilla/vanilla/venv/lib/python3.8/site-packages/django/utils/connection.py", line 45, in settings
self._settings = self.configure_settings(self._settings)
File "/data/www/vanilla/vanilla/venv/lib/python3.8/site-packages/django/db/utils.py", line 148, in configure_settings
databases = super().configure_settings(databases)
File "/data/www/vanilla/vanilla/venv/lib/python3.8/site-packages/django/utils/connection.py", line 50, in configure_settings
settings = getattr(django_settings, self.settings_name)
File "/data/www/vanilla/vanilla/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 87, in __getattr__
self._setup(name)
File "/data/www/vanilla/vanilla/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 74, in _setup
self._wrapped = Settings(settings_module)
File "/data/www/vanilla/vanilla/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 183, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/python3.8/python3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'proj'
I noticed the message of if not settings.DEBUG and not settings.ALLOWED_HOSTS: and checked my code in venilla/settings.py, which includes:
DEBUG = True
ALLOWED_HOSTS = ['*']
Furthermore, the following line is standard in my manage.py.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'vanilla.settings')
I checked all the libraries are installed correctly, tried to run
python manage.py makemigrations and
python manage.py check. Got the same error.
Really wondering what caused my problem. Can anyone help? Thank you.
After checking the system, I found the following line in /etc/profile.
export DJANGO_SETTINGS_MODULE=proj.settings
It seta the DJANGO_SETTINGS_MODULE to proj.settings and cannot be overwritten by manage.py. After removing it and rebooting the system, the problem is resolved.
I am trying to run migrations on my django project and I'm getting this really bizarre error that I haven't been able to address for a while now, and I don't understand it.
here's the error I'm getting:
Anaconda3\envs\mbt\lib\site-packages\django\db\models\query.py", line 415, in get
raise self.model.DoesNotExist(
django.contrib.auth.models.DoesNotExist: Group matching query does not exist.
I've tried to run python manage.py makemigrations
python manage.py migrate auth
python manage.py migrate my_app_name
I've also inserted the group names directly into my postgresql database just in case they're not posting. This error is preventing me from running the server locally.
I thought that the Group model was generated automatically and there wasn't much I needed to do to get started using it. It's definitely visible in my database.
any help would be greatly appreciated! thank you!!
here's the full traceback:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\nance\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\nance\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\nance\Anaconda3\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\nance\Anaconda3\lib\site-packages\django\core\management\base.py", line 366, in execute
self.check()
File "C:\Users\nance\Anaconda3\lib\site-packages\django\core\management\base.py", line 395, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\nance\Anaconda3\lib\site-packages\django\core\management\base.py", line 382, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\nance\Anaconda3\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\nance\Anaconda3\lib\site-packages\django\core\checks\urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "C:\Users\nance\Anaconda3\lib\site-packages\django\core\checks\urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "C:\Users\nance\Anaconda3\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\nance\Anaconda3\lib\site-packages\django\urls\resolvers.py", line 588, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\nance\Anaconda3\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\nance\Anaconda3\lib\site-packages\django\urls\resolvers.py", line 581, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\nance\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\nance\repo\project\app1\urls.py", line 28, in <module>
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
File "C:\Users\nance\Anaconda3\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Users\nance\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\nance\repo\project\app1\urls.py", line 5, in <module>
from app1 import views
File "C:\Users\nance\repo\project\app1\views.py", line 188, in <module>
class AllMentorsView(TemplateView):
File "C:\Users\nance\repo\project\app1\views.py", line 192, in AllMentorsView
mentor_group = Group.objects.get(name="Mentor")
File "C:\Users\nance\Anaconda3\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\nance\Anaconda3\lib\site-packages\django\db\models\query.py", line 417, in get
self.model._meta.object_name
django.contrib.auth.models.DoesNotExist: Group matching query does not exist.
So I just started learning django, and I was learning from this youtube video: https://www.youtube.com/watch?v=Nnoxz9JGdLU
So here is my directory map:
To_do
+To_do
+_pycache_
+_init_.py
+asgi.py
+settings.py
+urls.py
+wsgi.py
+todos
+_pycache_
+migrations
+_init_.py
+admin.py
+apps.py
+models.py
+tests.py
+urls.py
+views.py
+db.sqlite3
+manage.py
code of To_do/To_do/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('todos/', include('todos.urls'))
]
code of To_do/todos/urls.py
from django.urls import path
from . import views
urlpatterns =[
path('list/',views.list_todo_items)
]
code of To_do/todos/view.py
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def list_todo_items(request):
return HttpResponse('from list_todo_items')
My Issue:
After using the above codes with re-directions, clearly i'm messing up somewhere, as in the "main" urls.py file present in the project directory, when I'm running my server i get the error:
$ python3 manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/home/smith/.local/lib/python3.6/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/home/smith/.local/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/home/smith/.local/lib/python3.6/site-packages/django/core/management/base.py", line 395, in check
include_deployment_checks=include_deployment_checks,
File "/home/smith/.local/lib/python3.6/site-packages/django/core/management/base.py", line 382, in _run_checks
return checks.run_checks(**kwargs)
File "/home/smith/.local/lib/python3.6/site-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/smith/.local/lib/python3.6/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "/home/smith/.local/lib/python3.6/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "/home/smith/.local/lib/python3.6/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/smith/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 588, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/smith/.local/lib/python3.6/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/smith/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 581, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python3.6/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 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/smith/To_do/To_do/urls.py", line 21, in <module>
path('todos/', include('To_do.todos.urls'))
File "/home/smith/.local/lib/python3.6/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python3.6/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 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
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 'To_do.todos'
Clearly it is not able to find the "urls.py" file under "todos" folder, mentioned in "urls.py" in "To_do" folder.
As per the error path('todos/', include('To_do.todos.urls')) should be changed to: path('todos/', include('todo/',include('to_do.urls')) #to_do as the name of your app.
as per the error path('todos/', include('To_do.todos.urls')) should be changed to
path('todos/', include('todos.urls'))
Check to see if you added the todos app in the installed apps list of settings.py
INSTALLED_APPS = [
...
'todos.apps.TodosConfig'
]
stop the server ctrl + c then run server again python manage.py runserver
I accidentally pulled an old git repo of my Django build ( It's running on a Heroku dyno ) and it had overwritten my entire local build, I managed to restore it back to the latest git repo which was previously working on my local build ( but not my Heroku dyno ) and the server now won't run locally or on my live build?
Error from the shell:
python manage.py runserver
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/johnnie/.local/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/johnnie/.local/lib/python3.7/site-packages/django/core/management/__init__.py", line 345, in execute
settings.INSTALLED_APPS
File "/home/johnnie/.local/lib/python3.7/site-packages/django/conf/__init__.py", line 76, in __getattr__
self._setup(name)
File "/home/johnnie/.local/lib/python3.7/site-packages/django/conf/__init__.py", line 63, in _setup
self._wrapped = Settings(settings_module)
File "/home/johnnie/.local/lib/python3.7/site-packages/django/conf/__init__.py", line 142, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/johnnie/myproject/myproject/mysite/mysite/settings.py", line 141, in <module>
del DATABASES['default']['OPTIONS']['sslmode']
KeyError: 'OPTIONS'
edit:
del DATABASES['default']['OPTIONS']['sslmode']
was a section added by Heroku when committed by git.
removed this plus other Heroku changes which resolved issues.
Background
I have recently started to learn Python Django. I read that it was good practice to have separate settings file for different environments. Consequently I have tried to implement something similar to what is describe in the "Simple Package Organization for Environments" section of this wiki: https://code.djangoproject.com/wiki/SplitSettings
Problem
When I now run a django-admin command I get a ModuleNotFoundError. Below I have copy pasted the error log I get for "django-admin check --deploy". "python manage.py runserver --settings=CollegeComp.settings.development" works fine.
Things I've tried
I was reading that I may have to reset the DJANGO_SETTINGS_MODULE environment variable in my virtual environment. I entered "set DJANGO_SETTINGS_MODULE=CollegeComp.settings.development" but I still get the same error.
Python path
When I type the following in the shell with my virtual environment activated:
import sys
print(sys.path)
I get the following:
['C:\\Users\\myusername\\Documents\\UdemyDjango\\MyPersonalProject\\College-Project-master\\CollegeComp',
'C:\\Users\\myusername\\Anaconda3\\envs\\MyDjangoEnv\\python37.zip',
'C:\\Users\\myusername\\Anaconda3\\envs\\MyDjangoEnv\\DLLs',
'C:\\Users\\myusername\\Anaconda3\\envs\\MyDjangoEnv\\lib',
'C:\\Users\\myusername\\Anaconda3\\envs\\MyDjangoEnv',
'C:\\Users\\myusername\\Anaconda3\\envs\\MyDjangoEnv\\lib\\site-packages']
Error log
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\Scripts\django-admin-script.py", line 10, in <module>
sys.exit(execute_from_command_line())
File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\core\management\base.py", line 329, in run_from_argv
connections.close_all()
File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\db\utils.py", line 220, in close_all
for alias in self:
File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\db\utils.py", line 214, in __iter__
return iter(self.databases)
File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\utils\functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\db\utils.py", line 147, in databases
self._databases = settings.DATABASES
File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\conf\__init__.py", line 57, in __getattr__
self._setup(name)
File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\conf\__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\site-packages\django\conf\__init__.py", line 107, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Users\myusername\Anaconda3\envs\MyDjangoEnv\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'CollegeComp'
My project directory
CollegeComp
|-CollegeComp
|-settings
|-__init__.py
|-base.py
|-development.py
|-local.py
|-production.py
|-__init__.py
|-urls.py
|-wsgi.py
|-<my apps>
base.py
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
<rest of standard Django settings.py code>
development.py
from CollegeComp.settings.base import *
#Override base.py settings here
DEBUG = True
#Import local setting file
try:
from CollegeComp.settings.local import *
except:
pass
local.py
from CollegeComp.settings.base import *
#Override base settings here
DEBUG = True
production.py
from CollegeComp.settings.base import *
#Override base settings here
DEBUG = False
#Import local setting file
try:
from CollegeComp.settings.local import *
except:
pass
System info
Django version 2.1
Operating system: Windows 10
Python version: 3.7.0
I am grateful for any help I can get.