Coder Social home page Coder Social logo

django-cheatsheet's Introduction

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)

django-cheatsheet's People

Contributors

a-r-1 avatar codewithbishal avatar

Watchers

 avatar

Forkers

codewithbishal

django-cheatsheet's Issues

Content - Set up project environment

Installation instructions (if applicable) and commands (if applicable) for the following:

  • Describe one or more common tooling sets (e.g. terminal; an IDE (e.g. VS Code))
  • Describe one or more ways to create a project environment (e.g. using pipenv; venv; etc.)

N.B. If this content is short => add it to README.md; else => create and add to a new page within the Pages directory.

Create an example page - as a guideline document

  • create markdown page titled example-page.md
  • add in an example Django code snippet into the page
  • include consistent formatting and styling (refer to the readme.md if this section has been updated)

Content - Database migrations

  • Add content to show an example model (if one doesn’t already exist)
  • (if a new model has been added - reference it in settings.INSTALLED_APPS)
  • Show commands to perform database migrations

N.B. If this content is short => add it to README.md; else => create and add to a new page within the Pages directory

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.