How to create a project in Django?
Aspirant Programmer

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.

  • Total 1 Answer
  • 366
Can You answer this question?
Aspirant Programmer

Please find below steps to proceed work on Django, debug code and troubleshoot problems etc.

$django-admin startproject mysqlweb
$python 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 migrate

Create models in Custom app

Enable app by including in INSTALLED_APPS

$python makemigrations qna

$python sqlmigrate qna 0001 (sqlmigrate doesn't run migration in database it just prints what django is going to do in database)

$python migrate (Actually create tables in database)

$python shell
We’re using this instead of simply typing “python”, because sets the DJANGO_SETTINGS_MODULE environment variable, which gives Django the Python import path to your mysite/ file.

$python createsuperuser

print latest_poll_list
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 under INSTALLED_APPS as 'django_extensions'.

2- $pip install werkzeug

$python 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.