I get an error while trying to create superuser - python

I am new to Django and i am trying to create a superuser ( i'm on Linux mint) and everytime i get a very weird error that i did not get with other Django projects. The error is the following : ( I did not modify anything in the django project besides adding my app in the installed apps list and the url of the app in urls.)
File "/home/user/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 538, in url_patterns
iter(patterns)
TypeError: 'module' object is not iterable
During handling of the above exception, another exception occurred:
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 "/home/user/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/home/user/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/user/.local/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/user/.local/lib/python3.6/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 59, in execute
return super().execute(*args, **options)
File "/home/user/.local/lib/python3.6/site-packages/django/core/management/base.py", line 332, in execute
self.check()
File "/home/user/.local/lib/python3.6/site-packages/django/core/management/base.py", line 364, in check
include_deployment_checks=include_deployment_checks,
File "/home/user/.local/lib/python3.6/site-packages/django/core/management/base.py", line 351, in _run_checks
return checks.run_checks(**kwargs)
File "/home/user/.local/lib/python3.6/site-packages/django/core/checks/registry.py", line 73, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/user/.local/lib/python3.6/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/home/user/.local/lib/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/home/user/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 398, in check
warnings.extend(check_resolver(pattern))
File "/home/user/.local/lib/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/home/user/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 397, in check
for pattern in self.url_patterns:
File "/home/user/.local/lib/python3.6/site-packages/django/utils/functional.py", line 36, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/user/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 545, in url_patterns
raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'pleasework' from '/home/user/example.com/attempt/pleasework/__init__.py'>' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.
Can you please tell me what am i doing wrong? I tried creating a virtual enivronment but it did not work.

Please add more detailed code so I could try to help better, in any case, try the following -
Use the --username flag instead of directly passing a username:
python manage.py createsuperuser --username yourusername
Make sure you imported the model correctly in the admin.py file.
Check that this row appears in the INSTALLED_APPS:
'django.contrib.admin',
Try migrating the changes and then run createsuperuser.
I hope one of them solves the problem.

To check migrations, run python3 manage.py migrate.
Check the row appears in <project_root>/<project>/settings.py's INSTALLED_APPS list.
Then using python3 manage.py createsuperuser should work properly. It should prompt you:
Username (leave blank to use '<user>'):
E-mail:
Password:
where <user> is your computer's user name.

Related

CS50 Python & JS Web: Cannot operate website after trying to 'makemigrations'

I have been working through the Web with Python and Django with the CS50 course.
When i got to the stage of 'makemigrations' it didnt run and not i cant use the command 'runserver' either.
PS C:\Users\44777\code\airline> 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 "D:\Python38\lib\site-packages\django\urls\resolvers.py", line 591, in url_patterns
iter(patterns)
TypeError: 'module' object is not iterable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "D:\Python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "D:\Python38\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "D:\Python38\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run
self.check(display_num_errors=True)
File "D:\Python38\lib\site-packages\django\core\management\base.py", line 392, in check
all_issues = checks.run_checks(
File "D:\Python38\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "D:\Python38\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "D:\Python38\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "D:\Python38\lib\site-packages\django\urls\resolvers.py", line 409, in check
messages.extend(check_resolver(pattern))
File "D:\Python38\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "D:\Python38\lib\site-packages\django\urls\resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "D:\Python38\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "D:\Python38\lib\site-packages\django\urls\resolvers.py", line 598, in url_patterns
raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'flights.urls' from 'C:\\Users\\44777\\code\\airline\\flights\\urls.py'>' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.
PS C:\Users\44777\code\airline> python3 manage.py makemigrations
Traceback (most recent call last):
File "D:\Python38\lib\site-packages\django\urls\resolvers.py", line 591, in url_patterns
iter(patterns)
TypeError: 'module' object is not iterable
The above exception was the direct cause of the following exception:
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 "D:\Python38\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "D:\Python38\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\Python38\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "D:\Python38\lib\site-packages\django\core\management\base.py", line 368, in execute
self.check()
File "D:\Python38\lib\site-packages\django\core\management\base.py", line 392, in check
all_issues = checks.run_checks(
File "D:\Python38\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "D:\Python38\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "D:\Python38\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "D:\Python38\lib\site-packages\django\urls\resolvers.py", line 409, in check
messages.extend(check_resolver(pattern))
File "D:\Python38\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "D:\Python38\lib\site-packages\django\urls\resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "D:\Python38\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "D:\Python38\lib\site-packages\django\urls\resolvers.py", line 598, in url_patterns
raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'flights.urls' from 'C:\\Users\\44777\\code\\airline\\flights\\urls.py'>' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.
I was told that I could use the CS50 API to make things easier, but I am using VS Code on a Windows machine. I also know that the lecturer uses Mac. Does anyone know how to solve my problem? Thanks
-Max
EDIT:After going through the tutorial again from scratch i got the same problem. While looking through the syntax there was an error:
ModuleNotFoundError: No module named 'flights.url'
I went to the location that this was displayed and then realised i had forgotten a 's' in flights.urls. This was possibly not the problem i had in the past but now my code is allowing me to makemigrations.

AttributeError: 'NoneType' object has no attribute 'startswith' while makemigrations with manage.py in django

I am using Django 1.9.13 with python 2.7.5
When i make migrations i get below error.
I checked the database settings, all fine working with other app.
I couldn't figure out the solution.
I am using mysql DB at the backend.
I am using one app that is carried from test environment.
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/root/projects/misque/lib/python2.7/site-
packages/django/core/management/__init__.py", line 353, in
execute_from_command_line
utility.execute()
File "/root/projects/misque/lib/python2.7/site-p
Packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/root/projects/misque/lib/python2.7/site-
packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/root/projects/misque/lib/python2.7/site-
packages/django/core/management/base.py", line 398, in execute
self.check()
File "/root/projects/misque/lib/python2.7/site-
packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/root/projects/misque/lib/python2.7/site-
packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/root/projects/misque/lib/python2.7/site-
packages/django/core/checks/model_checks.py", line 28, in check_all_models
errors.extend(model.check(**kwargs))
File "/root/projects/misque/lib/python2.7/site-
packages/django/db/models/base.py", line 1178, in check
errors.extend(cls._check_fields(**kwargs))
File "/root/projects/misque/lib/python2.7/site-
packages/django/db/models/base.py", line 1255, in _check_fields
errors.extend(field.check(**kwargs))
File "/root/projects/misque/lib/python2.7/site-
packages/django/db/models/fields/__init__.py", line 925, in check
errors = super(AutoField, self).check(**kwargs)
File "/root/projects/misque/lib/python2.7/site-
packages/django/db/models/fields/__init__.py", line 208, in check
errors.extend(self._check_backend_specific_checks(**kwargs))
File "/root/projects/misque/lib/python2.7/site-
packages/django/db/models/fields/__init__.py", line 317, in
_check_backend_specific_checks
return connections[db].validation.check_field(self, **kwargs)
File "/root/projects/misque/lib/python2.7/site-
packages/django/db/backends/mysql/validation.py", line 18, in check_field
field_type = field.db_type(connection)
File "/root/projects/misque/lib/python2.7/site-
packages/django/db/models/fields/__init__.py", line 625, in db_type
return connection.data_types[self.get_internal_type()] % data
File "/root/projects/misque/lib/python2.7/site-
packages/django/db/__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/root/projects/misque/lib/python2.7/site-
packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/root/projects/misque/lib/python2.7/site-
packages/django/db/backends/mysql/base.py", line 184, in data_types
if self.features.supports_microsecond_precision:
File "/root/projects/misque/lib/python2.7/site-
packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/root/projects/misque/lib/python2.7/site-
packages/django/db/backends/mysql/features.py", line 53, in
supports_microsecond_precision
return self.connection.mysql_version >= (5, 6, 4) and Database.version_info
>= (1, 2, 5)
File "/root/projects/misque/lib/python2.7/site-
packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/root/projects/misque/lib/python2.7/site-
packages/django/db/backends/mysql/base.py", line 359, in mysql_version
with self.temporary_connection():
File "/usr/lib64/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/root/projects/misque/lib/python2.7/site-
packages/django/db/backends/base/base.py", line 564, in temporary_connection
cursor = self.cursor()
File "/root/projects/misque/lib/python2.7/site-
packages/django/db/backends/base/base.py", line 231, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/root/projects/misque/lib/python2.7/site-
packages/django/db/backends/base/base.py", line 204, in _cursor
self.ensure_connection()
File "/root/projects/misque/lib/python2.7/site-
packages/django/db/backends/base/base.py", line 199, in ensure_connection
self.connect()
File "/root/projects/misque/lib/python2.7/site-
packages/django/db/backends/base/base.py", line 170, in connect
conn_params = self.get_connection_params()
File "/root/projects/misque/lib/python2.7/site-
packages/django/db/backends/mysql/base.py", line 251, in
get_connection_params
if settings_dict['HOST'].startswith('/'):
AttributeError: 'NoneType' object has no attribute 'startswith'
Mysql DB is working fine and i can see db and tables.
App is added in settings.py
I found that there is another DATABASES config in settings. I deleted that. And now it is fine
In my case I was reading DB Credentials from env file ,it had some mistakes. when i fixed that issue solved.
First, Note: In Windows, you might have to use “set” instead of “export” in case you are loading your Database connection variables from a .env file
In python, we have 3 different ways to store credentials and read them using Python.
Storing them as system variables
Storing them as variables in your
virtual environment
Storing them in a .env file
Make sure, you choose the Most Convenient Way.
To Create a Global Environment Variable,
export varName=varValue
Ensure there are no spaces between the ‘=’. If you get an error “zsh: Bad Assignment”, it is probably caused because of space between the ‘=’.
Forexample, you can say create these variable
export globalSecretUser=global_uganda
export globalSecretKey = global_famitechsolutions
To access them
import os
print(os.environ)
# This will print a dictionary with
# all the global environment variables
We can use dictionary access methods to read the environment variables, i.e using .get() or [ ] As shown below
print(os.environ.get('globalSecretUser'))
print(os.environ.get('globalSecretKey'))
'''
global_uganda
global_famitechsolutions
'''
To update the environment variables, simply run the export statement again
export globalSecretUser=Updated_UgandaMountainGorillas
To remove an environment variable, we use the unset keyword
unset globalSecretUser
Important to note is that, If you try to access the variables(that do not exist) in Python, you will either get a KeyError or None depending on the method you use to access the values in the dictionary.
In my case, i was using export instead of set on my windows 7

TypeError: context must be a dict rather than Context

I'm trying to build a search engine into a django blog application and when I ran the command:
>>> manage.py build_solr_schema
I got this error:
Traceback (most recent call last):
File "C:\Users\KOLAPO\Google Drive\Python\Websites\mysite\manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\KOLAPO\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
utility.execute()
File "C:\Users\KOLAPO\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\KOLAPO\Anaconda3\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\KOLAPO\Anaconda3\lib\site-packages\django\core\management\base.py", line 330, in execute
output = self.handle(*args, **options)
File "C:\Users\KOLAPO\Anaconda3\lib\site-packages\haystack\management\commands\build_solr_schema.py", line 29, in handle
schema_xml = self.build_template(using=using)
File "C:\Users\KOLAPO\Anaconda3\lib\site-packages\haystack\management\commands\build_solr_schema.py", line 57, in build_template
return t.render(c)
File "C:\Users\KOLAPO\Anaconda3\lib\site-packages\django\template\backends\django.py", line 64, in render
context = make_context(context, request, autoescape=self.backend.engine.autoescape)
File "C:\Users\KOLAPO\Anaconda3\lib\site-packages\django\template\context.py", line 287, in make_context
raise TypeError('context must be a dict rather than %s.' % context.__class__.__name__)
TypeError: context must be a dict rather than Context.
What's wrong?
Note: I'm using Solr and Django-haystack for the search engine
I think this issue has been fixed by pull request 1504, but it looks like there hasn't been a release since then.

AttributeError: 'NoneType' object has no attribute 'is_relation'

this error comes up when I try to makemigrations for my python project.
I don't where to look because i have 5 apps with 5 models and views !
does it have relation with attributes with the same name in different models ?
(i added related_name='+' to avoid conflict names).
My django version is : 1.11.3
this is what my terminal returned when i tried to makemigrations :
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/user/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/home/user/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/user/.local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/user/.local/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/user/.local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 150, in handle
loader.project_state(),
File "/home/user/.local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 323, in project_state
return self.graph.make_state(nodes=nodes, at_end=at_end, real_apps=list(self.unmigrated_apps))
File "/home/user/.local/lib/python2.7/site-packages/django/db/migrations/graph.py", line 409, in make_state
project_state = self.nodes[node].mutate_state(project_state, preserve=False)
File "/home/user/.local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 92, in mutate_state
operation.state_forwards(self.app_label, new_state)
File "/home/user/.local/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 149, in state_forwards
delay = not old_field.is_relation
AttributeError: 'NoneType' object has no attribute 'is_relation'
In my case, this was caused by issues with the migrations. The easiest way to fix this, was to reset the migrations for the affected apps using django-reset-migrations: https://github.com/valdergallo/django-reset-migrations
I think something is wrong about your migrate files, check them if all exist and implemented. I think some your exist migration files are gone

Upgrading to Django 1.7. AssertionError: To use StatusField, the model 'ShellRequest' must have a STATUS choices class attribute

I was upgrading from Django 1.6 to 1.7. Python 2.7 is installed which is compatible with Django 1.7. While I did run the code python manage.py makemigrations, I got the following error message:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/m akemigrations.py", line 111, in handle
convert_apps=app_labels or None,
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/autodetector.py", line 42, in changes
changes = self._detect_changes(convert_apps, graph)
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/autodetector.py", line 109, in _detect_changes
self.old_apps = self.from_state.render(ignore_swappable=True)
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/state.py", line 67, in render
model.render(self.apps)
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/state.py", line 312, in render
body,
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 284, in __new__
new_class._prepare()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 344, in _prepare
signals.class_prepared.send(sender=cls)
File "/usr/local/lib/python2.7/dist-packages/django/dispatch/dispatcher.py", line 198, in send
response = receiver(signal=self, sender=sender, **named)
File "/usr/local/lib/python2.7/dist-packages/model_utils/fields.py", line 57, in prepare_class
% sender.__name__
AssertionError: To use StatusField, the model 'ShellRequest' must have a STATUS choices class attribute.
Reading the blogpost here, I couldn't figure out where to start. If anyone can give me a guideline how to deal with this issue would be appreciated.
The choices class field attribute is probably what you're looking for.
If you are using django-model-utils, the choices section of the package doc might help too.

Categories

Resources