From 711225f8e1b025d196f2dc8e211d72306d267e62 Mon Sep 17 00:00:00 2001 From: Kumari Ranjana Yadav Date: Sun, 15 Oct 2023 16:11:51 +0530 Subject: [PATCH] added Django framework --- src/App.jsx | 7 + src/Constants/index.js | 15 ++ .../Django/Installation.jsx | 55 +++++++ .../Django/Introduction-to-django.jsx | 136 ++++++++++++++++++ yarn.lock | 11 +- 5 files changed, 216 insertions(+), 8 deletions(-) create mode 100644 src/Python_Library_Pages/Django/Installation.jsx create mode 100644 src/Python_Library_Pages/Django/Introduction-to-django.jsx diff --git a/src/App.jsx b/src/App.jsx index a57f46a..ed04c37 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -10,6 +10,8 @@ import OperatorsBasics from "./Python_Library_Pages/Python_Basics/Intrduction-to import FunctionsBasics from "./Python_Library_Pages/Python_Basics/Introduction-to-Functions"; import PlayGround from "./Python/PlayGround"; +import DjangoIntro from "./Python_Library_Pages/Django/Introduction-to-django"; +import Installation from "./Python_Library_Pages/Django/Installation"; const App = () => { return ( @@ -40,6 +42,11 @@ const App = () => { }> } /> + {/* django */} + }> + } /> + } /> + {/* remaing routes*/} diff --git a/src/Constants/index.js b/src/Constants/index.js index 20b5fd4..3d0e080 100644 --- a/src/Constants/index.js +++ b/src/Constants/index.js @@ -44,5 +44,20 @@ export const subMenusList = [ }, ], }, + { + name: "Django", + title: "Django", + route: "/Django/Introduction-to-django", + children: [ + { + title: "Installation", + route: "Installation", + }, + { + title: "Introduction to Django", + route: "Introduction-to-django", + } + ], + }, /* remaining contents*/ ]; diff --git a/src/Python_Library_Pages/Django/Installation.jsx b/src/Python_Library_Pages/Django/Installation.jsx new file mode 100644 index 0000000..21cb4b6 --- /dev/null +++ b/src/Python_Library_Pages/Django/Installation.jsx @@ -0,0 +1,55 @@ +import React from 'react' + +const Installation = () => { + return ( +
+

Installation of Django...

+

I'll provide you with clear and concise steps to install Django for the first time.

+

Step 1: Install Python (if not already installed)

+

+ If Python is not already installed on your system, you need to install it. Django requires Python to work. You can download the latest version of Python from the official website: Python Downloads. Follow the installation instructions for your operating system. +

+
+

Step 2: Verify Python Installation

+

Open a command prompt or terminal and verify that Python is installed correctly by running:

+
+

python --version

+
+

This command should display the version of Python installed on your system.

+

Step 3: Install Django

+

Once you have Python installed, you can use Python's package manager, pip, to install Django. Open a command prompt or terminal and run the following command:

+
+

pip install django

+
+

This command will download and install the latest version of Django.

+
+

Step 4: Verify Django Installation

+

To ensure that Django has been installed successfully, run the following command:

+
+

django-admin --version

+
+

This command should display the installed Django version, indicating that Django is correctly installed on your system.

+

Step 5: Create a Django Project (Optional)

+

You can create a new Django project using the following command:

+
+

django-admin startproject projectname

+
+

Replace projectname with your preferred project name. This command will create a directory with your project name and the initial project structure.

+
+

Step 6: Start the Development Server (Optional)

+

Change into your project directory:

+
+

cd projectname

+
+

Now, you can start the development server:

+
+

python manage.py runserver

+
+

Your Django project is now running, and you can access it by opening a web browser and navigating to `http://localhost:8000/`.

+

Thank you :)

+

Follow pyLibLog to get more upadate about python

+
+ ) +} + +export default Installation \ No newline at end of file diff --git a/src/Python_Library_Pages/Django/Introduction-to-django.jsx b/src/Python_Library_Pages/Django/Introduction-to-django.jsx new file mode 100644 index 0000000..9587dfa --- /dev/null +++ b/src/Python_Library_Pages/Django/Introduction-to-django.jsx @@ -0,0 +1,136 @@ +import React from 'react' + +const DjangoIntro = () => { + return ( +
+

Introduction to Django

+

+ Django is a high-level, open-source web framework that makes it easier to build web applications quickly and efficiently. +

+

+ It was created with the goal of simplifying web development by providing a robust, flexible, and highly customizable toolkit for developers. +

+

+ Django is written in Python, which is known for its readability and ease of use, making it an excellent choice for both beginners and experienced developers. +

+

+ Django follows the Model-View-Controller (MVC) architectural pattern, but in Django, it's often referred to as the Model-View-Template (MVT). Here's a breakdown of the key components: +

+
    +
  • 1.Model: Defines the data structure and how it's stored in the database.
  • +
  • 2.View: Handles the presentation logic and user interface.
  • +
  • 3.Template: Defines the structure of the HTML to be rendered.
  • +
+

Advantages of Using Django:

+
    +
  • 1.Rapid Development: Django includes a range of built-in features, which means you can develop web applications faster.
  • +
  • 2. Security: Django has built-in security features to protect against common web vulnerabilities, such as SQL injection and cross-site scripting.
  • +
  • 3.Scalability: Django is suitable for building both small and large-scale web applications.
  • +
  • 4.Community and Documentation: Django has a large and active community, so you'll find plenty of documentation and resources to help you learn.
  • +
+

Creating a New Django project

+

Step 1: Create project using following cammand .

+
+

Open your terminal and navigate to the directory where you want to create your project. Run the following command to create a new Django project:

+
+

cd projectname

+
+

Replace "todoapp" with your preferred project name.

+
+

Step 2: Create a New App

+

In Django, a project is made up of one or more apps. We'll create a "tasks" app for our To-Do list. Run the following command:

+
+

cd todoapp

+

python manage.py startapp tasks

+

+

Step 3: Define Models

+

In your "tasks" app, define the data models. Edit the tasks/models.py file to include a simple model for your tasks:

+
+

from django.db import models

+ +

class Task(models.Model):

+

title = models.CharField(max_length=200)

+

completed = models.BooleanField(default=False)

+ +

def __str__(self):

+

return self.title

+
+

This model represents a task with a title and a completion status.


+

Step 4: Create Migrations and Apply Them

+

Run these commands to create database tables for your models:

+
+

python manage.py makemigrations

+

python manage.py migrate

+

+

Step 5: Create Views and Templates

+

Create views in your "tasks" app by editing the tasks/views.py file:

+
+

from django.shortcuts import render

+

from .models import Task

+

def task_list(request):

+

tasks = Task.objects.all()

+

{`return render(request, 'tasks/task_list.html', {'tasks': tasks})`}

+
+

Now, create a template for the task list in tasks/templates/tasks/task_list.html:

+
+
+          
+            {
+              `
+   
+  
+  
+    Task List
+  
+  
+    

Task List

+
    + {% for task in tasks %} +
  • {{ task.title }}
  • + {% endfor %} + /ul> + + +` + } +
    +
+
+
+

Step 6: URL Routing

+

Define URL patterns in your "tasks" app's `urls.py`:

+
+

from django.urls import path

+

from .import views

+

urlpatterns = [

+

path('', views.task_list, name='task_list'),

+

]

+
+

Then, include these URLs in your main project's urls.py:

+
+

from django.contribimport admin

+

from django.urls import path, include

+

urlpatterns = [

+

path('admin/', admin.site.urls),

+

path('', include('tasks.urls')),

+

]

+
+

Step 7: Running the Development Server

+

Start the development server by running this command:

+
+

python manage.py runserver

+
+

You can access your To-Do list app at `http://127.0.0.1:8000/`.

+
+

Step 8: Creating an Admin User

+

To access the admin interface, create a superuser account using:

+
+

python manage.py createsuperuser

+
+

You can now log in to the admin interface at `http://127.0.0.1:8000/admin/` to manage your tasks.

+

This is a basic To-Do list app. As you become more comfortable with Django, you can add features like task creation, task completion, user authentication, and more.

+
+ ) +} + +export default DjangoIntro \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 07e7ced..6f012d9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1279,10 +1279,10 @@ resolved "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.7.4.tgz" integrity sha512-Ja/Vfqe3HpuzRsG1oBtWTHk2PGZ7GR+2Vz5iYGelAw8dx32K0y7PjVuxK6z1nMpZOqAFsRUPCkK1YjJ56qJlgw== -"@esbuild/darwin-arm64@0.16.17": +"@esbuild/win32-x64@0.16.17": version "0.16.17" - resolved "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.16.17.tgz" - integrity sha512-/2agbUEfmxWHi9ARTX6OQ/KgXnOWfsNlTeLcoV7HSuSTv63E4DqtAc+2XqGw1KHxKMHGZgbVCZge7HXWX9Vn+w== + resolved "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.16.17.tgz" + integrity sha512-y+EHuSchhL7FjHgvQL/0fnnFmO4T1bhvWANX6gcnqTjtnKWbTvUMCpGnv2+t+31d7RzyEAYAd4u2fnIhHL6N/Q== "@eslint-community/eslint-utils@^4.2.0": version "4.4.0" @@ -4791,11 +4791,6 @@ fs.realpath@^1.0.0: resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== -fsevents@^2.3.2, fsevents@~2.3.2: - version "2.3.2" - resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz" - integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== - function-bind@^1.1.1: version "1.1.1" resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz"