I am trying to build my portfolio in Django and encountered an error after installing my app. It seems like it doesn't recognize the app on my INSTALLED_APPS. I've tried using 'blog' and 'blog.apps.BlogConfig' but nothing seems to be recognized.
I run the runserver with python manage.py runserver and python manage.py runserver but both returns ModuleNotFoundError: No module named 'blog.urls'
This is the whole traceback
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/core/management/base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/core/management/base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/urls/resolvers.py", line 398, in check
for pattern in self.url_patterns:
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/urls/resolvers.py", line 579, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/urls/resolvers.py", line 572, in urlconf_module
return import_module(self.urlconf_name)
File "/Users/usr/django-portfolio/env/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/usr/django-portfolio/portfolio/portfolio/urls.py", line 21, in <module>
path('', include('blog.urls'))
File "/Users/usr/django-portfolio/env/lib/python3.7/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/Users/usr/django-portfolio/env/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 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'blog.urls'
My INSTALLED_APPS is
INSTALLED_APPS = [
....
'blog'
]
URL in Settings
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('blog.urls'))
]
No module named 'blog.urls' means you don't have urls module inside blog.
You need to create a file named urls.py inside the blog app.
And you need to define some routes there.
After that below line
path('', include('blog.urls'))
will work fine.
Make sure you have structured your blog app and parent app properly. And you module path is set properly. For reference you can also see
Django Installed Apps Location
Related
I am using django 4.0.2 and django-tinymce 3.4.0 python 3.8
I am trying use tinymce as text editor by adding this line to main/urls.py
urlpatterns = [
...,
path(r'^tinymce/', include('tinymce.urls')),
....,
]
but is says no module named tinymce
i also tried import tinymce
installed after activating in virtual env using pip install django-tinymce.
enter codxception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/home/ubuntu/Desktop/guftaho/genv/lib/python3.8/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/home/ubuntu/Desktop/guftaho/genv/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 124, in inner_run
self.check(display_num_errors=True)
File "/home/ubuntu/Desktop/guftaho/genv/lib/python3.8/site-packages/django/core/management/base.py", line 438, in check
all_issues = checks.run_checks(
File "/home/ubuntu/Desktop/guftaho/genv/lib/python3.8/site-packages/django/core/checks/registry.py", line 77, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/home/ubuntu/Desktop/guftaho/genv/lib/python3.8/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/home/ubuntu/Desktop/guftaho/genv/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/home/ubuntu/Desktop/guftaho/genv/lib/python3.8/site-packages/django/urls/resolvers.py", line 448, in check
for pattern in self.url_patterns:
File "/home/ubuntu/Desktop/guftaho/genv/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/ubuntu/Desktop/guftaho/genv/lib/python3.8/site-packages/django/urls/resolvers.py", line 634, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/ubuntu/Desktop/guftaho/genv/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/ubuntu/Desktop/guftaho/genv/lib/python3.8/site-packages/django/urls/resolvers.py", line 627, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/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 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/ubuntu/Desktop/guftaho/guftaho/urls.py", line 23, in <module>
path(r'^tinymce/', include('tinymce.urls')),
File "/home/ubuntu/Desktop/guftaho/genv/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/usr/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 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'tinymce.urls'
any sugesstions, please?
Several files are missing from the pip install. Go to the GitHub repository and download the files manually from the tinymce directory. You can copy that to your site-packages directory in your virtual environment.
I just opened an issue about this myself.
https://github.com/jazzband/django-tinymce/issues/400
I'm just starting to learn Django through online lectures and I'm trying to run this command
python3 manage.py makemigrations
It returns the following error
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 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/management/base.py", line 368, in execute
self.check()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/management/base.py", line 392, in check
all_issues = checks.run_checks(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/checks/registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/urls/resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/urls/resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "/Library/Frameworks/Python.framework/Versions/3.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 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/dan/Documents/College/CS50 Web Programming/week 4/airline/airline/urls.py", line 21, in <module>
path("flights/", include("flights.url"))
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/Library/Frameworks/Python.framework/Versions/3.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 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'flights.url'
I've checked to make sure Python and Django are up to date, and that I have the correct app installed in INSTALLED_APPS
I supposse you misspelled the urls.py file in yourproject/urls.py
path('flights/', include('flights.urls'))
First, I typed from awsdjp.boardapp.views import * but error occurred.
Full Error is:
Traceback (most recent call last):
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\threading.py", line 926, in _bootstrap_inner
self.run()
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\USER\PycharmProjects\djangoProj\venv\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\USER\PycharmProjects\djangoProj\venv\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "C:\Users\USER\PycharmProjects\djangoProj\venv\lib\site-packages\django\core\management\base.py", line 395, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\USER\PycharmProjects\djangoProj\venv\lib\site-packages\django\core\management\base.py", line 382, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\USER\PycharmProjects\djangoProj\venv\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\USER\PycharmProjects\djangoProj\venv\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\USER\PycharmProjects\djangoProj\venv\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\USER\PycharmProjects\djangoProj\venv\lib\site-packages\django\urls\resolvers.py", line 407, in check
for pattern in self.url_patterns:
File "C:\Users\USER\PycharmProjects\djangoProj\venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\USER\PycharmProjects\djangoProj\venv\lib\site-packages\django\urls\resolvers.py", line 588, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\USER\PycharmProjects\djangoProj\venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\USER\PycharmProjects\djangoProj\venv\lib\site-packages\django\urls\resolvers.py", line 581, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\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\USER\PycharmProjects\djangoProj\awsdjp\awsdjp\urls.py", line 21, in <module>
path('boardapp/',include('boardapp.urls'))
File "C:\Users\USER\PycharmProjects\djangoProj\venv\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\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\USER\PycharmProjects\djangoProj\awsdjp\boardapp\urls.py", line 6, in <module>
from awsdjp.boardapp.views import *
ModuleNotFoundError: No module named 'awsdjp.boardapp'
I was googling about this issue .
Next, I typed
import sys
sys.path.insert(0,"C:\\Users\\USER\\PycharmProjects\\djangoProj\\")
That path is my directory's absolute path
And run but don't work ....
from awsdjp.boardapp.views import * part is not recognized.
If you want to import *, make sure that all the modules are imported in your boardapp/__init__.py
e.g.:
# boardapp/__init__.py
from . import admin
from . import apps
from . import models
from . import tests
from . import urls
from . import views
If you are trying to import from awsdjp\boardapp\urls.py, which is in the same folder as the views.py file, you can just use relative import like this:
from .views import *
If there is any bug in my code (code within a model that is used within a view which uses LoginRequiredMixin ) e.g. A bug like:
if (True: # <-- example bug to show how bugs like this are hidden
Then I get the following error:
"AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
django.core.exceptions.ImproperlyConfigured:
AUTH_USER_MODEL refers to model 'auth.User' that has not been installed
This makes it really hard to debug the code. I have figured out if I remove this line from my views.py:
from django.contrib.auth.mixins import LoginRequiredMixin
Even if I remove all instances where LoginRequiredMixin is used, just by importing it, it hides the true bug and generates the above auth error.
I have read: AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
My research shows most of the time this is due to "django.contrib.auth'" missing from INSTALLED_APPS, which you can see I have (settings.py snippet, Django 2.2):
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth', # <-- Important for this topic!
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp.apps.CommonConfig',
]
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.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
I tried adding this to above the mixim import but neither helped:
from django.contrib import auth
from django.contrib.auth.models import User
This part of the full traceback agrees with the above:
Traceback (most recent call last):
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\apps\registry.py", line 155, in get_app_config
return self.app_configs[app_label]
KeyError: 'auth'
Here is the traceback if I call makemigrations (This is what I expect):
C:\code\myproject\src>pipenv run python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\__init__.py", line 357, in execute
django.setup()
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\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 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 "C:\code\myproject\src\myapp\models.py", line 14, in <module>
from .sql import myapp_entry_clean, myapp_entry_grouping
File "C:\code\myproject\src\myapp\sql.py", line 68
if (True:
^
SyntaxError: invalid syntax
C:\code\myproject\src>
Here is the traceback with runserver:
C:\code\myproject\src>pipenv run python manage.py runserver
Watching for file changes with StatReloader
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python36\Lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\User\AppData\Local\Programs\Python\Python36\Lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\utils\autoreload.py", line 77, in raise_last_exception
raise _exception[0](_exception[1]).with_traceback(_exception[2])
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\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 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 "C:\code\myproject\src\myapp\models.py", line 14, in <module>
from .sql import myapp_entry_clean, myapp_entry_grouping
File "<string>", line None
SyntaxError: invalid syntax (sql.py, line 68)
Traceback (most recent call last):
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\apps\registry.py", line 155, in get_app_config
return self.app_configs[app_label]
KeyError: 'auth'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\contrib\auth\__init__.py", line 165, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL, require_ready=False)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\apps\registry.py", line 205, in get_model
app_config = self.get_app_config(app_label)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\apps\registry.py", line 162, in get_app_config
raise LookupError(message)
LookupError: No installed app with label 'auth'.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\commands\runserver.py", line 95, in handle
self.run(**options)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\commands\runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\utils\autoreload.py", line 579, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\utils\autoreload.py", line 564, in start_django
reloader.run(django_main_thread)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\utils\autoreload.py", line 272, in run
get_resolver().urlconf_module
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\urls\resolvers.py", line 564, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\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 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 "C:\code\myproject\src\linkcube\urls.py", line 20, in <module>
path('', include('common.urls')),
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\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 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 "C:\code\myproject\src\common\urls.py", line 5, in <module>
from . import views
File "C:\code\myproject\src\common\views.py", line 9, in <module>
from django.contrib.auth.mixins import LoginRequiredMixin
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\contrib\auth\mixins.py", line 3, in <module>
from django.contrib.auth.views import redirect_to_login
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\contrib\auth\views.py", line 10, in <module>
from django.contrib.auth.forms import (
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\contrib\auth\forms.py", line 20, in <module>
UserModel = get_user_model()
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\contrib\auth\__init__.py", line 170, in get_user_model
"AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'auth.User' that has not been installed
C:\code\myproject\src>
How do I make it so that the auth error is not falsely raised?
So the issue here is a python syntax error, but (maybe) since you are running Django framework, Django suppresses that and throws the missing model error.
Since python is interpreted language it threw an error for SyntaxError and since there was syntax error Django did not find auth model reference.
That's why you see both the errors there, python's SyntaxError and Django's ImproperlyConfigured error.
Django is kind enough to let you know that the Django's error is caused by the python's syntax error.
If you are getting that error message, I belive you are using a custom user model.
You may want to try to use AUTH_USER_MODEL on your relationships instead of the direct model User or the get_user_model method. This pretty much cleared the bug for me.
I got the solution from https://learndjango.com/tutorials/django-best-practices-referencing-user-model
The way to use AUTH_USER_MODEL is by first importing it from the settings usingfrom django.conf import settings and on the field that requires the relationship, you use it as, for example seller = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
I have a Django project connected to Gmail API.
When I try to do database migration it returns this:
C:\Users\Peter\Desktop\FastProject>python manage.py migrate FastProject
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", l
ine 371, in execute_from_command_line
utility.execute()
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", l
ine 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line
288, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line
332, in execute
self.check()
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line
364, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\commands\migrat
e.py", line 58, in _run_checks
issues.extend(super()._run_checks(**kwargs))
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line
351, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\registry.py", line
73, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\urls.py", line 13,
in check_url_config
return check_resolver(resolver)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\urls.py", line 23,
in check_resolver
return check_method()
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 397, i
n check
for pattern in self.url_patterns:
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\functional.py", line 36,
in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 536, i
n url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\functional.py", line 36,
in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 529, i
n urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\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 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 "C:\Users\Peter\Desktop\FastProject\FastProject\urls.py", line 21, in <module>
path('', include('mainApp.urls')),
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\conf.py", line 34, in incl
ude
urlconf_module = import_module(urlconf_module)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\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 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 "C:\Users\Peter\Desktop\FastProject\mainApp\urls.py", line 3, in <module>
from . import views
File "C:\Users\Peter\Desktop\FastProject\mainApp\views.py", line 2, in <module>
from quickstart import go
ModuleNotFoundError: No module named 'quickstart'
I have also tried 'makemigrations' and old one 'syncdb', but first one gives the same error and the second one isn't used anymore.I use SQLite3. This is in my settings :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'results_db.sqlite3'),
}
}
"quickstart" is a file from which I call a function. I guess all the names are correct, so I don't know what's the problem. This is error was before but I decided to think about it later.
Thanks.
It's definitely related to this line:
File "C:\Users\Peter\Desktop\FastProject\mainApp\views.py", line 2, in <module>
from quickstart import go
ModuleNotFoundError: No module named 'quickstart'
Looks like you're missing the quickstart module. Is it related to some tutorial? Maybe you forgot to activate your virtual environment?
Update:
You should use local imports or provide the full path to the package if you have such a project structure https://ibb.co/fdvaRJ:
from .quickstart import go
or
from mainApp.quickstart import go
Or you could put your quickstart.py module one level upper and just use
from quickstart import go
as you do now.
Don't forget to check out the official guide on packaging and modules in Python: https://docs.python.org/3/tutorial/modules.html#packages
I did some manipulations with that quickstart file. First I created in every folder 'init.py', then I created an empty folder in app directory and dragndropped there 'quickstart.py' and created there an empty "init" file too. Didn't work: the error just changed from ModuleNotFoundError: No module named 'quickstart' to ModuleNotFoundError: No module named 'api.quickstart'.
Then I deleted all "init" files created 2 minutes ago, put 'quickstart' file back to the root folder of my app and also drag'n'dropped an "init" file.
The error became just like " from quickstart import go
ImportError: cannot import name 'go' ". What I did next is just changed "from quickstart import go" to "import quickstart" and then called go function like "quickstart.go()"
Too much text so images for better understanding:
https://ibb.co/fdvaRJ
https://ibb.co/kzgPmJ
https://ibb.co/jyjVty