Each time i include the Django Rest Framework in my installed apps in my settings.py file, I get an error while starting my server.
The Error Message below:
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File"C:\Users\gchukwuma\AppData\Local\Programs\Python\Python37\lib\threading.py", line 926, in _bootstrap_inner self.run()
File"C:\Users\gchukwuma\AppData\Local\Programs\Python\Python37\lib\threading.py", line 870, in run self._target(*self._args, **self.kwargs)
File "C:\Users\gchukwuma\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper fn(*args, **kwargs)
File "C:\Users\gchukwuma\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 110, in inner_run autoreload.raise_last_exception()
File "C:\Users\gchukwuma\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception raise exception[1]
File "C:\Users\gchukwuma\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management_init.py", line 375, in execute autoreload.check_errors(django.setup)()
File "C:\Users\gchukwuma\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper fn(*args, **kwargs)
File "C:\Users\gchukwuma\AppData\Local\Programs\Python\Python37\lib\site-packages\django_init.py", line 24, in setup apps.populate(settings.INSTALLED_APPS)
File "C:\Users\gchukwuma\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\registry.py", line 122, in populate app_config.ready()
File "C:\Users\gchukwuma\AppData\Local\Programs\Python\Python37\lib\site-packages\rest_framework\apps.py", line 10, in ready from .checks import pagination_system_check # NOQA
ValueError: source code string cannot contain null bytes
The Settings.py file:
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'base.apps.BaseConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework'
]
Related
I deleted the pycache, migrations and DB of my code to start migrations again. But I realized that there might be another way to do it, so I discarded all the changes in VS code. I tried pulling the code from master, just in case. But it showed me that my branch was already up to date with master. So I ran makemigrations, but as I tried doing that, it showed me this error:
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2288.0_x64__qbz5n2kfra8p0\lib\threading.py", line 926, in _bootstrap_inner
self.run()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2288.0_x64__qbz5n2kfra8p0\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\core\management\__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2288.0_x64__qbz5n2kfra8p0\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 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django_filters'
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\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\core\management\base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\core\management\base.py", line 369, in execute
output = self.handle(*args, **options)
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\core\management\commands\runserver.py", line 95, in handle
self.run(**options)
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\core\management\commands\runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\utils\autoreload.py", line 599, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\utils\autoreload.py", line 584, in start_django
reloader.run(django_main_thread)
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\utils\autoreload.py", line 299, in run
self.run_loop()
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\utils\autoreload.py", line 305, in run_loop
next(ticker)
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\utils\autoreload.py", line 345, in tick
for filepath, mtime in self.snapshot_files():
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\utils\autoreload.py", line 361, in snapshot_files
for file in self.watched_files():
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\utils\autoreload.py", line 260, in watched_files
yield from iter_all_python_module_files()
File "C:\Users\gauta\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\utils\autoreload.py", line 105, in iter_all_python_module_files
return iter_modules_and_files(modules, frozenset(_error_files))
e 141, in iter_modules_and_files
resolved_path = path.resolve(strict=True).absolute()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2288.0_x64__qbz5n2kfra8p0\lib\pathlib.py", line 1166, in resolve
s = self._flavour.resolve(self, strict=strict)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2288.0_x64__qbz5n2kfra8p0\lib\pathlib.py", line 200, in resolve
return self._ext_to_normal(_getfinalpathname(s))
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '<frozen importlib._bootstrap>'
This has happened quite a lot times, and I cant seem to find a solution to it.
How do I resolve it?
Here is my settings.py:
INSTALLED_APPS = [
'rest_framework',
'django_filters',
'dashboard.apps.DashboardConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
REST_FRAMEWORK = { 'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema' }
On doing pip freeze > requirements.txt, i see this:
asgiref==3.2.7
astroid==2.4.0
colorama==0.4.3
Django==3.0.7
django-extensions==2.2.9
django-filter==1.1.0
django-smart-selects==1.5.6
djangorestframework==3.11.0
djangorestframework-filters==0.11.1
drfdocs==0.0.11
graphviz==0.14
isort==4.3.21
lazy-object-proxy==1.4.3
mccabe==0.6.1
pydotplus==2.0.2
pylint==2.5.0
pylint-django==2.0.15
pylint-plugin-utils==0.6
pyparsing==2.4.7
pytz==2020.1
six==1.13.0
sqlparse==0.3.1
toml==0.10.0
wrapt==1.11.2
Please help!!!
Your version is very old (https://github.com/carltongibson/django-filter/tree/56eaae15e4fab97483e1353080a0c320f18c1014#requirements)
and try moving below
INSTALLED_APPS = [
'dashboard.apps.DashboardConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'django_filters',
]
Please install django-filter package and add to installed apps
pip install django-filter
Then add 'django_filters' to your INSTALLED_APPS.
INSTALLED_APPS = [
...
'django_filters',
]
I know there are Duplicates of this question, but they didn't solve the issue.
my django app is conflicting between django-user-acccounts; account and allauth.account
M Installed App
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts.apps.AccountsConfig',
'django.contrib.sites',
# 'allauth',
'allauth.account', # django-allauth # conflict
'allauth.socialaccount',
'crispy_forms',
'account', # django-user-accounts #conflict
'pinax.referrals',
'kingEstateCore',
'widget_tweaks',
]
I've tried renaming the account package inside my site_packages but no success.
I've also tried adding AppConfig but there was no apps.py module insite my site_packages/account.
Any Ideas pls
Error TraceBack
Watching for file changes with StatReloader
Exception in thread django-main-thread:
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\Desktop\KingAfam\KingENV\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\USER\Desktop\KingAfam\KingENV\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\USER\Desktop\KingAfam\KingENV\lib\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "C:\Users\USER\Desktop\KingAfam\KingENV\lib\site-packages\django\core\management\__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\USER\Desktop\KingAfam\KingENV\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\USER\Desktop\KingAfam\KingENV\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\USER\Desktop\KingAfam\KingENV\lib\site-packages\django\apps\registry.py", line 95, in populate
"duplicates: %s" % app_config.label)
django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: account
I am using djangae with some third party applications like all-auth, django-invitations and django rest framework. When I hit python manage.py migrate I get the following error.
AttributeError: type object 'ContentType' has no attribute 'objects'
The full trace is following
Traceback (most recent call last):
File "manage.py", line 26, in <module>
execute_from_command_line(sys.argv)
File "/home/salman/Workspace/chaipani/lib/djangae/core/management/__init__.py", line 43, in execute_from_command_line
return _execute_from_command_line(djangae_namespace.sandbox, argv, parser=djangae_parser, **overrides)
File "/home/salman/Workspace/chaipani/lib/djangae/core/management/__init__.py", line 68, in _execute_from_command_line
return django_management.execute_from_command_line(argv)
File "/home/salman/Workspace/chaipani/lib-vendor/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/home/salman/Workspace/chaipani/lib-vendor/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/salman/Workspace/chaipani/lib-vendor/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/salman/Workspace/chaipani/lib-vendor/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/salman/Workspace/chaipani/lib-vendor/django/core/management/commands/migrate.py", line 227, in handle
self.verbosity, self.interactive, connection.alias, apps=post_migrate_apps, plan=plan,
File "/home/salman/Workspace/chaipani/lib-vendor/django/core/management/sql.py", line 53, in emit_post_migrate_signal
**kwargs
File "/home/salman/Workspace/chaipani/lib-vendor/django/dispatch/dispatcher.py", line 193, in send
for receiver in self._live_receivers(sender)
File "/home/salman/Workspace/chaipani/lib-vendor/django/contrib/auth/management/__init__.py", line 63, in create_permissions
ctype = ContentType.objects.db_manager(using).get_for_model(klass)
AttributeError: type object 'ContentType' has no attribute 'objects'
My installed apps:
INSTALLED_APPS = [
'djangae',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'djangae.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'djangae.contrib.security',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
'invitations',
]
Any help anyone?
I am creating a app in django and I want to fetch data from mongolab.
But,I don't know how to connect mongolab to django.
I had connect mongodb to django but now I want to connect with mongolab.
How to do this?
I have used this in my setting.py file,
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'djangotoolbox',
'app'
)
And in DATABASE:,
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine',
'NAME': '*****',
'USER': '*****',
'PASSWORD': '******',
'HOST': 'ds129469.mongolab.com',
'PORT': '26469'
}
}
And after running command, python manage.py runserver
I get following error,
life#life-All-Series:~/mongo/env1/project7/project$ python manage.py runrver
/home/life/.local/lib/python2.7/site-packages/djangotoolbox/db/utils.py:1: RemovedInDjango19Warning: The django.db.backends.util module has been renamed. Use django.db.backends.utils instead.
from django.db.backends.util import format_number
/home/life/.local/lib/python2.7/site-packages/djangotoolbox/db/utils.py:1: RemovedInDjango19Warning: The django.db.backends.util module has been renamed. Use django.db.backends.utils instead.
from django.db.backends.util import format_number
Performing system checks...
System check identified no issues (0 silenced).
Unhandled exception in thread started by <function wrapper at 0x7fbad4b24c08>
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/django/utils/autoreload.py", line 229, in wrapper
fn(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 116, in inner_run
self.check_migrations()
File "/usr/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 168, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "/usr/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 19, in __init__
self.loader = MigrationLoader(self.connection)
File "/usr/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 47, in __init__
self.build_graph()
File "/usr/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 191, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/usr/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
self.ensure_schema()
File "/usr/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File "/home/life/.local/lib/python2.7/site-packages/django_mongodb_engine/base.py", line 179, in table_names
return self.connection.database.collection_names()
File "/home/life/.local/lib/python2.7/site-packages/pymongo/database.py", line 488, in collection_names
ReadPreference.PRIMARY) as (sock_info, slave_okay):
File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/home/life/.local/lib/python2.7/site-packages/pymongo/mongo_client.py", line 699, in _socket_for_reads
with self._get_socket(read_preference) as sock_info:
File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/home/life/.local/lib/python2.7/site-packages/pymongo/mongo_client.py", line 663, in _get_socket
server = self._get_topology().select_server(selector)
File "/home/life/.local/lib/python2.7/site-packages/pymongo/topology.py", line 121, in select_server
address))
File "/home/life/.local/lib/python2.7/site-packages/pymongo/topology.py", line 97, in select_servers
self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: ds129469.mongolab.com:29469: [Errno -2] Name or service not known
I am trying to install django-notification app[1] and I get an error when I give manage.py syncdb.
The error states: EnvironmentError: NOTIFICATIONS was not found.
I have installed django-notification using setup tools successfully. This is my stack trace.
File "C:\Tools\Python26\lib\site-packages\django\core\management\__init__.py",
line 438, in execute_manager
utility.execute()
File "C:\Tools\Python26\lib\site-packages\django\core\management\__init__.py",
line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Tools\Python26\lib\site-packages\django\core\management\base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Tools\Python26\lib\site-packages\django\core\management\base.py", line 219, in execute
self.validate()
File "C:\Tools\Python26\lib\site-packages\django\core\management\base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "C:\Tools\Python26\lib\site-packages\django\core\management\validation.py", line 36, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "C:\Tools\Python26\lib\site-packages\django\db\models\loading.py", line 146, in get_app_errors
self._populate()
File "C:\Tools\Python26\lib\site-packages\django\db\models\loading.py", line 61, in _populate
self.load_app(app_name, True)
File "C:\Tools\Python26\lib\site-packages\django\db\models\loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "C:\Tools\Python26\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "build\bdist.win32\egg\django_notifications\models.py", line 20, in <module>
File "build\bdist.win32\egg\django_notifications\backends\__init__.py", line 23, in get_available_backends
File "build\bdist.win32\egg\django_notifications\backends\__init__.py", line 90, in get_class_instance_by_key
File "build\bdist.win32\egg\django_notifications\backends\xmpp.py", line 33, in __init__
File "build\bdist.win32\egg\django_notifications\backends\__init__.py", line 5
5, in get_settings
EnvironmentError: NOTIFICATIONS was not found.
Any ideas what went wrong?
*Added settings.INSTALLED_APPS part (corrected 'django-notifications' entry to 'notification' as suggested)*
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'grappelli',
'filebrowser',
'tinymce',
'south',
'avatar',
'django.contrib.admin',
'notification',
'myproject.main',
)
[1] https://github.com/jtauber/django-notification
For whatever reason, you've decided to add django_notifications to settings.INSTALLED_APPS instead of notification. Fix this.