{"id":19361025,"url":"https://github.com/skp3214/fullstack-development-django","last_synced_at":"2026-04-26T20:31:37.945Z","repository":{"id":245623933,"uuid":"818788167","full_name":"skp3214/FullStack-Development-Django","owner":"skp3214","description":"A repository to learn fullstack web development using python framework django with different project examples.","archived":false,"fork":false,"pushed_at":"2025-04-11T06:26:55.000Z","size":3996,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-04T05:33:29.399Z","etag":null,"topics":["django","form","fullstack-development","model","model-form","mvt-architecture","pip","pipenv","templates","venv","view"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skp3214.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-06-22T21:43:44.000Z","updated_at":"2025-04-11T06:26:59.000Z","dependencies_parsed_at":"2024-09-17T23:21:25.206Z","dependency_job_id":"45d10dd0-59c1-4bf7-90ef-c993bb4f1f3f","html_url":"https://github.com/skp3214/FullStack-Development-Django","commit_stats":null,"previous_names":["skp3214/backenddevelopment-django"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/skp3214/FullStack-Development-Django","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skp3214%2FFullStack-Development-Django","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skp3214%2FFullStack-Development-Django/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skp3214%2FFullStack-Development-Django/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skp3214%2FFullStack-Development-Django/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skp3214","download_url":"https://codeload.github.com/skp3214/FullStack-Development-Django/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skp3214%2FFullStack-Development-Django/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32312212,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T19:15:34.056Z","status":"ssl_error","status_checked_at":"2026-04-26T19:15:15.467Z","response_time":129,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","form","fullstack-development","model","model-form","mvt-architecture","pip","pipenv","templates","venv","view"],"created_at":"2024-11-10T07:20:15.542Z","updated_at":"2026-04-26T20:31:37.929Z","avatar_url":"https://github.com/skp3214.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FullStack-Development (Django)\n\n## Introduction To Django Web Framework\n\n## Django\n- Django is an open-source web development framework written in Python.\n- Django follows MVT([Model](/models.md)-[View](/views.md)-[Templates](/templates.md)) pattern\n- Django provides features such as `Templates`, `Libraries`, and `APIs`.\n- Django is popular because of its ease of scalability.\n- Django is a `Full-Stack` framework, but developers can use it to create `backend` systems and connect them with any frontend framework like `React`, `Angular`, `Vue`, etc., through `API`.\n  \n  ![alt text](/assets/image-2.png)\n\n## Django Project Setup In VSCode\n1. **Python Interpreter**: First, you need a Python interpreter. Select it from the `Command Palette` in VSCode.\n  \n  ![alt text](/assets/image-1.png)\n\n2. **Create a Virtual Environment**:\n   - Use the following command:\n     ```sh\n     python -m venv .venv\n     ```\n   - `.venv` is the folder name where the virtual environment is created. You can name this folder anything you like.\n   - Python recommends using a virtual environment to build Python applications.\n   - A `Virtual Environment` is an isolated environment that has its own copy of the interpreter and libraries to avoid conflicts with the global Python installation.\n\n3. **Activate the Virtual Environment**:\n   - Use the following command:\n     ```sh\n     .venv\\Scripts\\activate\n     ```\n\n4. **Install the Django Framework**:\n   - Use the following command:\n     ```sh\n     pip install Django\n     ```\n   - To deactivate the virtual environment, simply use:\n     ```sh\n     deactivate\n     ```\n\n## Project and Apps\n### Project \u0026 Apps\n- In Django, a `Project` represents an entire web application.\n- An `App` is a sub-module of a project.\n- A `Project` can have multiple `Apps`.\n  \n  ![alt text](/assets/image-3.png)\n\n- A Django `Project` is a Python package that includes the configuration for the database, various sub-modules known as `Apps`, and other settings specific to Django.\n\n## Steps to Create a Django Project and App\n\n### 1. Install Django\nFirst, ensure you have Django installed. You can install it using `pip`:\n```sh\npip install django\n```\n\n### 2. Create a Django Project\nTo create a new Django project, use the `django-admin` command followed by `startproject` and your project name. For example, to create a project named `myproject`:\n```sh\ndjango-admin startproject myproject\n```\n\nThis will create a directory structure like this:\n```\nmyproject/\n    manage.py\n    myproject/\n        __init__.py\n        settings.py\n        urls.py\n        wsgi.py\n        asgi.py\n```\n![alt text](/assets/image-4.png)\n\n### 3. Navigate to Your Project Directory\nChange into the project directory:\n```sh\ncd myproject\n```\n\n### 4. Create a Django App\nInside your project directory, create a new Django app using the `manage.py` script. For example, to create an app named `myapp`:\n```sh\npython manage.py startapp myapp\n```\n\nThis will create a directory structure like this:\n```\nmyapp/\n    __init__.py\n    admin.py\n    apps.py\n    models.py\n    tests.py\n    views.py\n    migrations/\n        __init__.py\n```\n![alt text](/assets/image-5.png)\n\n### 5. Register the App in the Project\nTo make Django recognize the app, you need to add it to the `INSTALLED_APPS` list in your project's `settings.py` file.\n\nOpen `myproject/settings.py` and add `'myapp',` to the `INSTALLED_APPS` list:\n```python\nINSTALLED_APPS = [\n    ...\n    'myapp',\n]\n```\n![alt text](/assets/image-6.png)\n\n### 6. Run Migrations\nDjango manages the databases operations with the ORM techniques.\nORM, or Object-Relational Mapping, is a programming technique used to interact with a database using an object-oriented paradigm. In the context of Django, ORM allows developers to work with databases using Python classes and objects rather than writing raw SQL queries.\n\n#### What is ORM?\n\n1. **Definition**:\n   - **Object-Relational Mapping (ORM)** is a method of mapping a database schema to an object-oriented model. It allows developers to manipulate database entries as if they were regular Python objects.\n\n2. **How ORM Works in Django**:\n   - Django ORM translates Python code into SQL queries. It provides a high-level abstraction over the database that lets you interact with it using Python instead of SQL.\n   - You define your database schema as Python classes (called models), and Django handles the SQL behind the scenes to create and manage the database tables.\n\n3. **Advantages of Using ORM**:\n   - **Simplicity**: ORM abstracts the database operations, making it easier for developers to interact with the database.\n   - **Portability**: The same ORM code can work with different databases (e.g., SQLite, PostgreSQL, MySQL) without modification.\n   - **Security**: ORM helps prevent SQL injection attacks by using parameterized queries.\n\n#### Example of ORM in Django\n\n#### Defining a Model in App\n\nIn Django, you define your database schema using models. Here is an example of a simple model representing a `Book`:\n\n```python\nfrom django.db import models\n\nclass Book(models.Model):\n    title = models.CharField(max_length=200)\n    author = models.CharField(max_length=100)\n    published_date = models.DateField()\n\n    def __str__(self):\n        return self.title\n```\n\n#### Creating a Migration\n\nAfter defining your models, you need to create and apply migrations to generate the corresponding database tables. This is how Django manages the database schema.\n\n1. **Create Migrations**:\n   ```sh\n   python manage.py makemigrations\n   ```\n\n2. **Apply Migrations**:\n   ```sh\n   python manage.py migrate\n   ```\nThe above two commands should be run whenever a new model is created or any change is done in existing model.\n![alt text](/assets/image-9.png)\n#### Using the ORM\n\nOnce the migrations are applied, you can use the ORM to create, retrieve, update, and delete records in the database.\n\n0. **Open the Django Shell**\n   ```sh\n   python manage.py shell\n   ```\n1. **Create a Record**:\n   ```python\n   from myapp.models import Book\n   book = Book(title=\"Django for Beginners\", author=\"John Doe\", published_date=\"2023-01-01\")\n   book.save()\n   ```\n\n2. **Retrieve Records**:\n   ```python\n   all_books = Book.objects.all()\n   book = Book.objects.get(id=1)\n   ```\n\n3. **Update a Record**:\n   ```python\n   book = Book.objects.get(id=1)\n   book.title = \"Advanced Django\"\n   book.save()\n   ```\n\n4. **Delete a Record**:\n   ```python\n   book = Book.objects.get(id=1)\n   book.delete()\n   ```\n5. **Exit from the shell**\n   ```sh \n   exit() \n   ``` \n![alt text](/assets/image-8.png)\n\n### 7. Create a View\nDefine a simple view in `myapp/views.py`. For example:\n```python\nfrom django.http import HttpResponse\n\ndef home(request):\n    return HttpResponse(\"Hello, world! This is my home page.\")\n```\n\n### 8. Map the View to a URL\nCreate a URL configuration for your app. In `myapp`, create a file named `urls.py` and add:\n```python\nfrom django.urls import path\nfrom . import views\n\nurlpatterns = [\n    path('', views.home, name='home'),\n]\n```\n\nThen, include this URL configuration in your project’s `urls.py` file (`myproject/urls.py`):\n```python\nfrom django.contrib import admin\nfrom django.urls import path, include\n\nurlpatterns = [\n    path('admin/', admin.site.urls),\n    path('', include('myapp.urls')),\n]\n```\n\n### 9. Run the Development Server\nStart the development server to see your project in action:\n```sh\npython manage.py runserver\n```\n\nOpen a web browser and go to `http://127.0.0.1:8000/`. You should see the message \"Hello, world! This is my home page.\"\n\n![alt text](/assets/image-7.png)\n\n## MVT Architecture\nThe MVT (Model-View-Template) architecture is the design pattern used by Django to build web applications. It is a variation of the MVC (Model-View-Controller) pattern tailored to suit the needs of web development with Django. Here’s an overview of each component in the MVT architecture:\n\n![alt text](/assets/image-11.png)\n\n### MVT Components\n\n1. **Model**:\n   - The **Model** is the data access layer. It defines the structure of the database, including the tables and their relationships, as well as the methods to interact with the data.\n   - In Django, models are defined as Python classes, which Django's ORM (Object-Relational Mapping) then translates into database tables.\n   - Example:\n     ```python\n     from django.db import models\n\n     class Book(models.Model):\n         title = models.CharField(max_length=200)\n         author = models.CharField(max_length=100)\n         published_date = models.DateField()\n     ```\n\n2. **View**:\n   - The **View** is the business logic layer. It processes user requests, interacts with the model to retrieve data, and determines what data to send back to the user.\n   - Views in Django are Python functions or classes that receive web requests and return web responses.\n   - Example:\n     ```python\n     from django.shortcuts import render\n     from .models import Book\n\n     def book(request):\n         books = Book.objects.all()\n         return render(request, 'book.html', {'books': books})\n     ```\n\n3. **Template**:\n   - The **Template** is the presentation layer. It defines how the data received from the view should be displayed to the user.\n   - Templates in Django are HTML files with Django Template Language (DTL) which allows for dynamic content insertion.\n   - Example (`home.html`):\n     ```html\n     \u003c!DOCTYPE html\u003e\n     \u003chtml\u003e\n     \u003chead\u003e\n         \u003ctitle\u003eHome Page\u003c/title\u003e\n     \u003c/head\u003e\n     \u003cbody\u003e\n         \u003ch1\u003eBook List\u003c/h1\u003e\n         \u003cul\u003e\n             {% for book in books %}\n                 \u003cli\u003e{{ book.title }} by {{ book.author }}\u003c/li\u003e\n             {% endfor %}\n         \u003c/ul\u003e\n     \u003c/body\u003e\n     \u003c/html\u003e\n     ```\n\n### How MVT Works Together\n\n1. **Request**:\n   - A user sends a request to the Django application by entering a URL in the browser.\n\n2. **URL Routing**:\n   - Django uses URLconf to map the URL to a specific view. The `urls.py` file contains these mappings.\n   - Example (`urls.py`):\n     ```python\n     from django.urls import path\n     from . import views\n\n     urlpatterns = [\n         path('', views.home, name='home'),\n     ]\n     ```\n\n3. **View Processing**:\n   - The view function associated with the URL is called. This view processes the request, interacts with the model to get data, and passes the data to the template.\n   - Example view (`views.py`):\n     ```python\n     def home(request):\n         books = Book.objects.all()\n         return render(request, 'home.html', {'books': books})\n     ```\n\n4. **Template Rendering**:\n   - The template receives the data from the view and renders it into HTML to be sent back to the user.\n   - Example template (`home.html`):\n     ```html\n     \u003cul\u003e\n         {% for book in books %}\n             \u003cli\u003e{{ book.title }} by {{ book.author }}\u003c/li\u003e\n         {% endfor %}\n     \u003c/ul\u003e\n     ```\n\n5. **Response**:\n   - The rendered HTML is sent back to the user’s browser as a response, which displays the data in a web page.\n  \n  ![alt text](/assets/image-10.png)\n\n### Summary\n\nThe MVT architecture in Django allows for a clear separation of concerns:\n- **Model**: Manages the data and database interactions.\n- **View**: Contains the business logic and handles user requests.\n- **Template**: Defines the presentation and how data is displayed to the user.\n\nThis structure helps in organizing code, making it more maintainable and scalable.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskp3214%2Ffullstack-development-django","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskp3214%2Ffullstack-development-django","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskp3214%2Ffullstack-development-django/lists"}