KEMBAR78
Open Django Folder in Vs Code | PDF | Software | Computing
0% found this document useful (0 votes)
9 views4 pages

Open Django Folder in Vs Code

This document provides a step-by-step guide for setting up a Django project in Visual Studio Code, including creating a virtual environment, installing Django, and starting a new project. It details the folder structure of a Django project, the creation of new apps, and how to manage views and URLs for routing. Additionally, it explains the importance of modular design in Django applications and how to set up a basic frontend with HTML templates.

Uploaded by

sparrow763901
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Open Django Folder in Vs Code

This document provides a step-by-step guide for setting up a Django project in Visual Studio Code, including creating a virtual environment, installing Django, and starting a new project. It details the folder structure of a Django project, the creation of new apps, and how to manage views and URLs for routing. Additionally, it explains the importance of modular design in Django applications and how to set up a basic frontend with HTML templates.

Uploaded by

sparrow763901
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Open Django folder in VS Code

 Python -m venv .venv [command in terminal]


 .venv / Scripts / activate
 Install Django using  pip install django [package install ]

Create project using command

django-admin startproject Djangoproject .

Manage.py – command line utility [ for Django project related command run with manage.py]

Ex: to create new app

Database link and command

For serving

Inside Django project

Folder structure

 __Init__py (we must have) for we can read pakage fron virtual environment
 Asgi – not used at development time [asyncronous] -- same time multiple request and response
support config is hold here
 Wsgi -- not used at development time [ server related configuration have] – For moving over project
to cloud

 Setting.py and urls.py [we are going to work in this project]

Serve the project

 Python manage.py runserver [ for run the server or our site]


Red lines are come [ migration – db related] – just warning
Extension sqliteviewer

.venv / Scripts / activate [ when ever we start fresh in the day]

Please use default browser - chrome

Create new Django Apps:

Complete project is separated is called moduling.

Folder structure is created when we try to create App – this is called modules
 For Industry management site [Moduals]
o Inventory
o Payment mgt
o Sales mgt
o Stock management
 Python manage.py startapp Inventory (app name or module name)
o Migration folder is created [for database config]
o Init.py – apps are needs to read in venv
o Models – also for db
o Admin.py - For access Django admin area
o Test – it will not use development time [for testing]
o Views.py - we going to write All kind of logical works(codes) we can done here
o Apps.py – it is used for converting realtime Django app [we are not going to change anything
at all]
 All folders are creating stand alone, so we can reuse for other projects as well
o How we can add this app to our project
 Setting.py [inside project]
 Installed Apps list
o We need to add our App name inside ‘ ’
o Ex: ‘Inventory’
 For our project – we can create any number of Apps
o But for front end – only 1 App we will create
o For backend any no. of Apps we can create

HTML Page create in Django

>>> Python manage.py startapp Frontend

Inside frontend
Create templates
View, Test, Models, Admin, migration - No need of these files (delete these)

 Inside front end


o Templates – folder
o __init__
o Apps.py

Inside template
 Create index.html (any no.of html files we can create inside templates)
When we run this application - For view the index in browser, we need to create
view function and url
 We can create view function in Inventory [ backend App ]

Backend App – Inventory


 Views.py - In imported render from Django-shortcuts [ Already created by defaults]

[ we can create class based and function based view ]

 def Homepage(request):
 return
render(request,'index.html')

How this function is called and show the HTML page in browser is:

Based on user request. Sends the request to server and server responds

Now created the proper view function using request

For each view function we need to create url link

For each app we going to create urls


Inside Inventory App – we need to create urls.py [ paste the below code]

 from django.urls import path


o copy this code from Django project file  urls.py
if this path is pasted then only, we can link all our apps into project urls

after that our view functions are import to the urls.py [to Inventory app]
from .views import * [ All the view function are imported from views.py]
[for real time allocation we may create many no.of view function]
urlpatterns=[] ( create empty list ) – for connecting base routing

goto Django project -----


by default admin page only rendered
urls.py
 before do the change run the server
the initial page run from Django urls page
 path('admin/', admin.site.urls), [just for understanding]

from django.urls import path,include [ we need to add include after path]


because if we need to link other app’s urls

path('inventory/',include('Inventory.urls')), [ we need add this line]

we are going to create another app name : ordermgt


 create urls.py
 copy the codes from Inventory  urls.py.
 admin in Browse
 after/ Inventory
Goto Inventory  urls.py
urlpatterns = [
path('home/', Homepage)
]

You might also like