• Tips & Tricks

    • To debug python project codes
      Use breakpoints at desired place in the program, use ‘Shift+F9’.
    • To create/edit/display database using pycharm
      – View Menu -‘Tool Windows’ option – Database  –  choose desired database                    applications.
    • About Django Root Directory/Python Project Files – 
      • When we create a python project using django framework (called python package), this framework itself creates a root directory of the python project with the project name on it.This project file contains some files and folder, which provide the very basic functionality to our website and helps for building full scaled website.
      • The django root directory means, the directory which contains the manage.py file. Root directory also contains additional files like db.sqlite, which is a database file and are present when we will be migrating our project.

      • Django root directory is the default app which Django provides to us. 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 we create.The files in root directory have their specific purposes. 

      • The Python files are – 
      • __init__.py – 
        • The __init__.py files are required to make Python application/project that contains python packages.
        • This is the first file to be loaded in a module of python project/application, so we can use it to execute code that we want to run each time a module is loaded, or specify the sub-modules to be exported.The__init__ is a special Python method that is automatically called when memory is allocated for a new object. 
        • The sole purpose of __init__ is to initialize the values of instance members for the new object i.e. it can also execute  initialization code for the package or set the __all__ variable values.
        • 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. 
      • asgi.py – 
      • settings.py – 
        • The settings.py is the central configuration for all Django projects where a series of variables in this file to configure things like Django applications, databases, templates and middleware, among other things.
        • The settings.py file uses reasonable default values for practically all variables, when a Django application transitions into the real world.
        • We can make a series of adjustments as per need, to efficiently run the Django application in this file.
        • The settings.py is the main file where we add/store all our applications and middleware applications. This file also contains the inbuilt/installed applications and middleware information which are with Django framework.
      • urls.py –
        • In urls.py, the most important thing is the matching of “url patterns” as tuple. It’s where we define the mapping between URLs and views. 
        • A mapping is a tuple in URL patterns like − from django. conf. urls import patterns, include, url from django.
        •  This file provides the address of the resource (images, web pages, web-applications etc.) and other resources required for the website.
        • The main purpose of this file is to connect the web-apps with the project.
        • This file by default adds one URL to the admin app. The path () of this file takes two arguments.First is the URL to be searched in the URL bar on the local server and second is the file we want to run when the URL request is matched. The admin is the pre-made application and the file is URL’s file of the app. 
      • wsgi.py – 
        • Django is based on python which uses WSGI server for web development. This file is mainly concerned with to deploy the applications on Apache servers or any other server because Django is still work as backend and we need its support with different servers. 

    • About Python App Files – 
      • __init__.py – 
      • admin.py –
      • apps.py – 
      • models.py –
      • tests.py – 
      • views.py –
        • This file is simply a Python file that takes a web request and returns a web response.

        • This response can be the HTML contents of a Web page, or a redirect, or a 404 error, or an XML document, or an image, or anything, really.

        • This code can live anywhere we want, as long as it’s on our Python path.

        • For the sake of putting the code somewhere, the convention is to put views in a file called views.py, placed in our project or application directory.

        • A View is the user interface — what you see in your browser when you render a website.

    • migrations –
    • templates  –
      • To create html pages, css, java script files etc.
      • Templates are typically used as an intermediate format written by developers to programmatically produce one or more desired output formats, commonly HTML, XML or PDF.
    • manage.py
      • This file shows the results of running tasks using the  manage.py utility.
      • This file is the command line utility of the project and is used 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.
      • The use some commands of manage files are runserver (to start the server), makemigrations(for integrating our project with files or apps), migrate(to add those migrations we made in the makemigrations command with the whole project.) etc.



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.