importerror: cannot import name jsonfield
Cause of importerror: cannot import name jsonfield from django_mysql.models
This error importerror: cannot import name jsonfield from django_mysql.models can arise while you are running your python file even though you have installed simplejson in your system. The error appears as follows:
It may be possible that your pip freeze command shows the following code:
alabaster==0.7.12 Babel==2.7.0 bcdoc==0.16.0 boto3==0.0.21 botocore==1.0.0b3 certifi==2019.9.11 chardet==3.0.4 defusedxml==0.6.0 Django==1.8.2 django-bulk-update==1.1.4 django-cors-headers==2.0.2 django-facebook==6.0.3 django-pgjsonb==0.0.15 django-redis==4.2.0 django-revproxy==0.9.7 djangorestframework==3.1.3 djangorestframework-httpsignature==1.0.0 docutils==0.15.2 elasticsearch==1.6.0 facebook-sdk==1.0.0 filemagic==1.6 futures==2.2.0 geopy==1.11.0 google-api-python-client==1.5.0 httplib2==0.14.0 httpsig==1.3.0 idna==2.8 Jinja2==2.10.3 jmespath==0.7.1 MarkupSafe==1.1.1 mock==1.0.1 mongoengine==0.10.0 msgpack-python==0.5.6 nose==1.3.7 oauth2client==2.2.0 oauthlib==3.1.0 Pillow==2.8.2 psycopg2==2.8.4 py2neo==2.0.8 pyasn1==0.4.7 pyasn1-modules==0.2.7 pycryptodome==3.9.0 Pygments==2.4.2 PyJWT==1.7.1 pymongo==3.0.3 PySocks==1.7.1 python-dateutil==2.8.0 python-social-auth==0.2.10 python3-memcached==1.51 python3-openid==3.1.0 python3-pika==0.9.14 pytz==2019.3 redis==2.10.3 requests==2.2.1 requests-oauthlib==1.2.0 rsa==4.0 simplejson==3.7.3 six==1.12.0 snowballstemmer==2.0.0 Sphinx==1.3.1 sphinx-rtd-theme==0.1.9 sphinxcontrib-httpdomain==1.3.1 treelib==1.3.0 twilio==5.6.0 Unidecode==1.1.1 uritemplate==0.6 urllib3==1.10.1
Solution
A JSON-encoded response can be produced with the aid of the HttpResponse subclass JsonResponse. Application/json is the set Content-Type header by default. Data, the first parameter, must be a dict object.
Data can be sent and stored using the JSON syntax. Using JavaScript object notation, JSON is text. JSON may be parsed from strings or files using the JSON library. The library converts JSON into a Python list or dictionary. Additionally, it can transform lists or dictionaries in Python into JSON strings.
JSON fields are handy in situations when we frequently need to add developer data to developer websites. Make a Django project first, then an app. Please complete all the necessary steps, including adding the app to INSTALLED APPS, creating URLs, creating a simple model, and rendering the form in an HTML file.
These problems mainly come due to the problems in the versions of the different modules we are using. In this case, the user is using Django 1.8.2 which is not compatible. So to solve this problem one needs to use the Django 1.9 version with the JSON file. This solution is the major reason behind the above problem.
Also Read: failed to load plugin flowtype declared in package.json