Skip to content

remarkeyable/Django

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Django

Django is a popular Python web framework designed to help developers rapidly build secure, scalable web applications. Get the skills to build web applications with Django, work with data and forms, and deploy your Django applications in this fast-paced learning path.

Features of Django

  • Object-Relational mapping
  • URL routing
  • HTML templating
  • Form handling
  • Unit testing
  • Admin Site
  • Authentication
  • Caching

To start

django-admin startproject namefile

Files in the Project Folder

  • manage.py
    • Runs Commands
  • __init__.py
    • Tells Python that the folder contains Python code
  • wsgi.py & asgi.py
    • define how web servers can communicate with web applications
  • settings.py
    • configures the Django project
  • urls.py
    • routes web requests based on URL

To run the program

cd foldername
python manage.py runserver

Django Apps

  • A component in a Django project
  • A folder with a set of Python files
  • Each app fits a specific purpose

Examples of Django Apps

  • Blog
  • Forum
  • Wiki

Creating first app

python manage.py startapp filename

Every app needs to register on settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'playground' #-> my app
]

჻჻჻჻჻ views.py

request handler

from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.

def say_hello(response):
   return HttpResponse('Hello World')

add urls.py on the app folder

from django.urls import path
from . import views

#UrlConf
urlpatterns = [
   path('hello/', views.say_hello)
]

჻჻჻჻჻ main folders urls.py

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
   path('admin/', admin.site.urls),
   path('playground/', include('playground.urls'))
]

Using Templates

from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.

def say_hello(request):
   return render(request,'hello.html')

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published