7👍
You get this error because a django management command’s handle()
method is not supposed to return anything but a string -if you read the traceback, you easily find out that the error happens in the base class (in django/core/management/base.pydjango/core/management/base.py), which tries to print out the value returned by your command.
The point is that is makes no sense returning anything else from a management command: a management command is a command-line tool and is expected either to work by side effects (modifying something in your database / on your filesystem / etc) or to generate some text output that can be either displayed or fed to another command line program (in the unix tradition where you pipe commands together).
The fix is plain obvious: format your result as a string before returning it, ie (example with a json output but you could choose to generate csv or xml or whatever suits you):
import json
class Command(BaseCommand):
help = "TODO: describe"
def handle(self, *args, **options):
result = engagement_level_mapping()
return json.dumps(result, indent=2)
0👍
From the error we can infer that you are checking a dict
instead of a string
in your if condition
. Check the value assigned for msg
variable.
- [Django]-Counting distinct elements in Django ArrayField
- [Django]-Graphene-Django nested filters (relay)
- [Django]-Type object has not attribute 'get_or_create'
- [Django]-Force re-collectstatic with django static?
0👍
Use your stack traces. The stack trace tells you exactly where the error occured and why. In yours, it says that it’s on line 111
in File "/home/xlm/.virtualenvs/y/lib/python3.5/site-
. From what the details say, it looks like you have a variable
packages/django/core/management/base.py"msg
that you expect to be a string (I assume this because it is called with a method that is a string method.
However, it also looks like this is a django block of code in the django framework. This means that you are calling a method that eventually calls that code. I assume that you are suppose to pass in a string but instead you pass in a dictionary.
So look around for code that results in that traceback (We can’t here because we don’t have your entire project and the code you gave us isn’t it) and check the value you are trying to pass in.
- [Django]-Pass kwargs for the view in reverse; django 1.5
- [Django]-Open() "/root/project/static/*.css" failed (13: Permission denied) nginx