How to Return JSON Encoded Response for a non-dict object
In DJango, an HttpResponse sub-class helps to create a JSON-encoded response. It was called Serialized-Object response in Django < 1.7. Its default Content-Type header is set to application/JSON. The first parameter (data set), should be a dict instance. If non-dict object is passed in as the first parameter, a TypeError will be raised. To fix this error, we just need to add a parameter called “safe” to False in the method call JsonResponse. TypeError: In order to allow non-dict objects to be serialized set the…
Django errors while working with components
1) OperationalError at /admin/csv_app/invoicefile/add/ no such table: csv_app_invoicefile ==>solve this error by cmd makemigrations csv_app migrate 2)System check identified no issues (0 silenced). You have 6 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): csv_app. Run ‘python manage.py migrate’ to apply them. July 13, 2021 – 14:55:01 Django version 3.2.5, using settings ‘proj3.settings’ Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK. ==>to fix this error, go to cmd enter: $python manage.py makemigrations csv_app $python manage.py migrate…
Inner class Meta
In Django this class works like post_meta in WordPress. In Django, it acts as a configuration class and keeps the configuration data in one place. Class Meta is the place in your code logic where your model.fields MEET With your form.widgets. So under Class Meta() you create the link between your model’ fields and the different widgets you want to have in your form. Model metadata is “anything that’s not a field”, such as ordering options (ordering), database table name (db_table), or human-readable singular and…
OperationalError, no such column.
OperationalError at /orders/ no such column: orders.customer_id Request Method: GET Request URL: http://localhost:9000/orders/ Django Version: 3.1.2 Exception Type: OperationalError Exception Value: no such column: orders.customer_id Exception Location: /Users/xxx/django/db/backends/sqlite3/base.py in execute, line 355 Python Executable: /Users/xxx/Programs/Python/Python38-32 Python Version: 3.8.1 You are trying to add a non-nullable field ‘customer_id’ to snippet without a default; we can’t do that (the database needs something to populate existing rows). Please select a fix: 1) Provide a one-off default now (will be set on all existing rows) 2) Quit, and let…