0% found this document useful (0 votes)
3 views5 pages

Python Notes Set 9

This document provides a concise guide to the basics of Django, covering installation, project and app creation, and the structure of Django applications. It details how to define models, create views, set up URLs, and use templates. Key commands and code snippets are included for quick reference.

Uploaded by

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

Python Notes Set 9

This document provides a concise guide to the basics of Django, covering installation, project and app creation, and the structure of Django applications. It details how to define models, create views, set up URLs, and use templates. Key commands and code snippets are included for quick reference.

Uploaded by

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

Page 1: Django Basics

Install:

pip install django

Create project:

django-admin startproject mysite

Run server:

python manage.py runserver


Page 2: Django App Structure

Create app:

python manage.py startapp myapp

Structure:

- models.py

- views.py

- urls.py

- templates/
Page 3: Django Models

Define model in models.py:

class Person(models.Model):

name = models.CharField(max_length=100)

age = models.IntegerField()

Migrate:

python manage.py makemigrations

python manage.py migrate


Page 4: Django Views and URLs

views.py:

def index(request):

return HttpResponse("Hello Django")

urls.py:

from django.urls import path

from . import views

urlpatterns = [ path('', views.index) ]


Page 5: Django Templates

Use render():

return render(request, 'index.html', {'name': 'Alice'})

Templates in templates/ folder

{{ variable }}

{% for item in list %}

{{ item }}

{% endfor %}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy