Django Start Project and App

Now that you have installed Django. It is time to start a new project and application.

Django Start Project

In any version of django you can start a new project with the below command:

django-admin startproject project_name

The project directory will initially look like this:

    project_name/
        manage.py
        project_name/
            __init__.py
            settings.py
            urls.py
            asgi.py
            wsgi.py
                                

After this you may move to project directory. The outer folder with project name is merely a container housing you project, manage.py and the database.

cd project_name

Django manage.py

manage.py helps manage you project by allowing you to run the command-line arguments same as django-admin.

    Available subcommands:

    [auth]
        changepassword
        createsuperuser
    
    [contenttypes]
        remove_stale_contenttypes
    
    [django]
        check
        compilemessages
        createcachetable
        dbshell
        diffsettings
        dumpdata
        flush
        inspectdb
        loaddata
        makemessages
        makemigrations
        migrate
        sendtestemail
        shell
        showmigrations
        sqlflush
        sqlmigrate
        sqlsequencereset
        squashmigrations
        startapp
        startproject
        test
        testserver
    
    [sessions]
        clearsessions
    
    [staticfiles]
        collectstatic
        findstatic
        runserver
                                    

Django migrate

migrate is used to apply migrations or publish changes. It is usually followed after makemigrations. The use of migrate here is to apply migrations for built-in apps like admin, auth, contentypes and sessions.

python manage.py migrate
    Operations to perform:
      Apply all migrations: admin, auth, contenttypes, sessions
    Running migrations:
      Applying contenttypes.0001_initial... OK
      Applying auth.0001_initial... OK
      Applying admin.0001_initial... OK
      Applying admin.0002_logentry_remove_auto_add... OK
      Applying contenttypes.0002_remove_content_type_name... OK
      Applying auth.0002_alter_permission_name_max_length... OK
      Applying auth.0003_alter_user_email_max_length... OK
      Applying auth.0004_alter_user_username_opts... OK
      Applying auth.0005_alter_user_last_login_null... OK
      Applying auth.0006_require_contenttypes_0002... OK
      Applying auth.0007_alter_validators_add_error_messages... OK
      Applying auth.0008_alter_user_username_max_length... OK
      Applying sessions.0001_initial... OK
                                

Django runserver

Now that our skeleton django project is ready we just need to run a local development server that comes built-in.

python manage.py runserver
django project