Configure the basic setup initialization in a new Django project

  • Firstly Create a Django project named "myproj":

    django-admin startproject myproj

  • Now open this django project in vs code.
  • Create a Django app named "app" inside the "myproj" project:

    django-admin startapp app

  • In the "myproj/settings.py" file, add "app" to the "INSTALLED_APPS" list:

    INSTALLED_APPS = [
        # ...
        'app',
    ]

  • Now create templates | static | media these three folder in root directory, where exist manage.py file. and now configure in settings.py file in located in myproj folder.

    import os

    TEMPLATES_DIR = os.path.join(BASE_DIR,'templates')
    STATIC_DIR = os.path.join(BASE_DIR,'static')
    STATIC_ROOT = os.path.join(BASE_DIR,'staticfiles')
    MEDIA_DIR = os.path.join(BASE_DIR,'media')



    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [TEMPLATES_DIR],
            'APP_DIRS': True,
            'OPTIONS': {
                'context_processors': [
                    'django.template.context_processors.debug',
                    'django.template.context_processors.request',
                    'django.contrib.auth.context_processors.auth',
                    'django.contrib.messages.context_processors.messages',
                ],
            },
        },
    ]



    STATIC_URL = '/static/'

    MEDIA_ROOT = MEDIA_DIR
    MEDIA_URL = 'media/'

    STATICFILES_DIRS=[
        STATIC_DIR,
    ]

  • That's it.

No comments:

Post a Comment