Skip to content

A compilation of useful code snippets to create, set up, and develop a Django project.

Notifications You must be signed in to change notification settings

a-r-1/django-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

django-cheatsheet

A compilation of useful code snippets to create, set up, and develop a Django project.

Code Of Conduct:

  • TBA...

Styling Guidelines:

  • TBA...

Requirements:

  • Python
  • Pip
  • Django

Table of Contents

Installing Django


pip install django

Creating a project


django-admin startproject project-name

Starting the Server


python manage.py runserver

Creating an app


python manage.py startapp AppName

Django Models


from django.db import models

class ModelName(models.Model):
ModelName_id = models.AutoField

Django Views

  • Views.py

from django.http import HttpResponse

def index(request):
return HttpResponse("cheatsheet")

URL Patterns


from django.contrib import admin
from django.urls import path
from . import views

urlpatterns = [
path('admin/', admin.site.urls),
path('', views.index, name='index'),
path('about/', views.about, name='about'),
path('contact/', views.contact, name='contact'),
]

Render a page using views.py


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

Creating a migration


python manage.py makemigrations

Applying the migration


python manage.py migrate


Here (TBA)

About

A compilation of useful code snippets to create, set up, and develop a Django project.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published