Here's the entire Django Cheat Sheet in one place for easy copying:
Use the package manager pip to install foobar.
pip install django
django-admin startproject projectname
python manage.py startapp appname
python manage.py runserver
python manage.py createsuperuser
python manage.py makemigrations
python manage.py migrate
python manage.py shell
python3 -m venv venv
source venv/bin/activate # On Linux/Mac
venv\Scripts\activate # On Windows
class MyModel(models.Model):
field_name = models.CharField(max_length=255)
from django.shortcuts import render
def my_view(request):
return render(request, 'template_name.html')
from django.urls import path
from . import views
urlpatterns = [
path('my-view/', views.my_view, name='my-view'),
]
<!DOCTYPE html>
<html>
<head>
<title>{{ page_title }}</title>
</head>
<body>
<h1>{{ heading }}</h1>
</body>
</html>
STATIC_URL = '/static/'
class MyForm(forms.Form):
my_field = forms.CharField()
from django.contrib import admin
from .models import MyModel
admin.site.register(MyModel)
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Regards : Engr Umair Facebook