What are the steps to start working on Django and debug in code to troubleshoot problems, also about how to deal with database in django? a brief explanation from start to proceed.
Please find below steps to proceed work on Django, debug code and troubleshoot problems etc.
$django-admin startproject mysqlweb
$python manage.py startapp polls
$pip install mysqlclient (for python3, when using mysql database with django)
Some of these applications make use of at least one database table, though, so we need to create the tables in the database before we can use them. To do that, run the following command:
$python manage.py migrate
Create models in Custom app
Enable app by including in INSTALLED_APPS
$python manage.py makemigrations qna
$python manage.py sqlmigrate qna 0001 (sqlmigrate doesn't run migration in database it just prints what django is going to do in database)
$python manage.py migrate (Actually create tables in database)
$python manage.py shell
We’re using this instead of simply typing “python”, because manage.py sets the DJANGO_SETTINGS_MODULE environment variable, which gives Django the Python import path to your mysite/settings.py file.
$python manage.py createsuperuser
assert False, latest_poll_list
To start debuggin in django while doing development you will need to follow below steps and get to go:
1- $pip install django_extensions
Now include in settings.py under INSTALLED_APPS as 'django_extensions'.
2- $pip install werkzeug
$python manage.py runserver_plus
You have set all required things for debugging, just need to write below statement where you want to debug:
3- assert False, latest_poll_list
It will display in browser and start debugging, here latest_poll_list is result set of records.