Skip to main content

Posts

Showing posts from July, 2021

Django cheatsheet

  Django Cheatsheet Loading... What is Django? Python-based web framework used for rapid development. Installing Django + Setup pip install django Copy Creating a project The below command creates a new project django - admin startproject projectName Copy Starting a server The below command starts the development server. python manage . py runserver Copy Django MVT Django follows MVT(Model, View, Template) architecture. Sample Django Model The model represents the schema of the database. from django . db import models class Product ( models . Model ) : // Product is the name of our model product_id = models . AutoField Copy Sample views.py View decides what data gets delivered to the template. from django . http import HttpResponse def index ( request ) : return HttpResponse ( '' Django CodeWithHarry Cheatsheet '' ) Copy Sample HTML Template A sample .html file that contains HTML, CSS and Javascript. < !DOCTYPE html > < html lang = "en"

Flask cheatsheet

  Flask Cheatsheet Loading... Importing Flask from flask import Flask Copy Most used import functions These are some of the most used import functions from flask import Flask , render_template , redirect , url_for , request Copy Boilerplate This is the basic template or barebone structure of Flask. from flask import Flask app = Flask ( __name__ ) @app . route ( "/" ) def hello_world ( ) : return "<p>Hello, World!</p>" app . run ( ) Copy route(endpoint) This is to make different endpoints in our flask app. @app . route ( "/" ) Copy Route method Allowing get and post requests on an endpoint. methods = [ 'GET' , 'POST' ] Copy Re-run while coding This is used to automatically rerun the program when the file is saved. app . run ( debug = True ) Copy Change host This is used to change the host. app . run ( host = '0.0.0.0' ) Copy Change port This is used to change the port. app . run ( port = 80 ) Copy SQ