Quick Contact

    Python Tutorial
    Python Panda Tutorial
    Python Selenium
    Python Flask Tutorial
    Python Django
    Interview Questions & Answers

    Django Project Layout

    When you create a Django project, the Django framework itself creates a root directory of the project with the project name on it. That contains some files and folder, which provide the very basic functionality to your website and on that strong foundation you will be building your full scaled website.

    Files in the Django Project Root Directory

    By root directory, we mean about the directory which contains your manage.py file. Additional files like db.sqlite, which is a database file may be present when we will be migrating our project.

    Django root directory is the default app which Django provides you. It contains the files which will be used in maintaining the whole project.

    The name of Django root directory is the same as the project name you mentioned in django-admin startproject [projectname]. This root directory is the project’s connection with Django.

    The files in root directory have their specific purposes and once you will understand them Django will look much more logical to you. All these files are just for completing special purposes and they are in very logical order.

    We will be starting with the manage.py file.

    1. manage.py

      This file is the command line utility of the project and we will be using this file only to deploy, debug and test with the project.

      The file contains the code for starting the server, migrating and controlling the project through command-line.

      This file provides all the functionality as with the django-admin and it also provides some project specific functionalities. During this tutorial, we will frequently use some of the commands that are runserver, makemigrations, migrate etc. We will be using these commands more frequently than others.

      runserver is a command to start the test server provided by Django framework and that is also one of the advantages of Django over other frameworks.

      makemigrations is the command for integrating your project with files or apps you have added in it. This command will actually check for any new additions in your project and then add that to the same.

      migrate, the last command is to actually add those migrations you made in the last command with the whole project. You can get the idea as the former command is used for saving the changes in the file and later one to actually apply that change to the whole project then the single file.

    2. my_project

      my_project is the python package of the project. It has the configuration files of project settings.

    1. __init__.py

      The __init__.py file is empty and it exists in the project for the sole purpose of telling the python interpreter that this directory is a package. That’s one of the standard rules of python packages.

      Although we won’t be doing anything on this file.

    2. settings.py

      The settings.py is the main file where we will be adding all our applications and middleware applications. As the name suggests this is the main settings file of the Django project. This file contains the installed applications and middleware information which are installed on this Django project.

      Every time you install a new app or custom application you will be adding that in this file.

    3. urls.py

      urls.py file contains the project level URL information. URL is universal resource locator and it provides you with the address of the resource (images, webpages, web-applications) and other resources for your website.

      The main purpose of this file is to connect the web-apps with the project. Anything you will be typing in the URL bar will be processed by this urls.py file. Then, it will correspond your request to the designated app you connected to it.

      1st is the URL to be searched in the URL bar on the local server and 2nd is the file you want to run when that URL request is matched, the admin is the pre-made application and the file is URL’s file of that app. This file is the map of your Django project.

    4. wsgi.py

      Django is based on python which uses WSGI server for web development. This file is mainly concerned with that and we will not be using this file much.

      wsgi is still important though if you want to deploy the applications on Apache servers or any other server because Django is still backend and you will need its support with different servers.

      But you need not to worry because for every server there is a Django middleware out there which solves all the connectivity and integration issues and you just have to import that middleware for your server, it’s very simple.



    Apply now for Advanced Python Training Course

    Copyright 1999- Ducat Creative, All rights reserved.

    Anda bisa mendapatkan server slot online resmi dan terpercaya tentu saja di sini. Sebagai salah satu provider yang menyediakan banyak pilihan permainan.